行が見つからない場合、「結果が見つかりません」というメッセージを表示するにはどうすればよいですか?
while($row = $query->fetch(PDO::FETCH_ASSOC))
{
echo $row['name'];
}
もう一つ..
$kittens = $query->fetchAll(PDO::FETCH_ASSOC))
if(!$kittens )
{
//Nada
}
else
{
foreach($kittens as $kitten)
{
}
}
$matched = false;
while($row = $query->fetch(PDO::FETCH_ASSOC))
{
$matched = true;
echo $row['name'];
}
if(!$matched)
echo "no any";
Just an alternative solution, you could add a if condition.
if ($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo $row['name'];
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo $row['name'];
}
} else {
echo "no results found";
}