I'm having an issue getting this code to work properly. It is working when a record is found and displays the data but does not execute else and echo when a record in the db is not found. I am guessing is has to do with how I am structuring my code. I have tried this a couple different ways and am having no luck. I am using a sqlite3 database
$recID = '55';
$results2 = $db2->query("SELECT * FROM Movies WHERE TMDBid = '$recID'");
while($row2 = $results2->fetchArray()){
if(!empty($row2['id'])){
$Runtime = $row2['Runtime'];
$Budget = $row2['Budget'];
$Revenue = $row2['Revenue'];
$Production = $row2['Production'];
echo $Runtime.'<br>';
echo $Budget.'<br>';
echo $Revenue.'<br>';
echo $Production.'<br><br>';
}else{
echo 'No Record Exists';
}
}
I have tried it this way as well and this way works when no record is found but will not display data when the record exists.
$recID = '55';
$results2 = $db2->query("SELECT * FROM Movies WHERE TMDBid = '$recID'");
if($results2->fetchArray() !== false){
while($row2 = $results2->fetchArray()){
$Runtime = $row2['Runtime'];
$Budget = $row2['Budget'];
$Revenue = $row2['Revenue'];
$Production = $row2['Production'];
echo $Runtime.'<br>';
echo $Budget.'<br>';
echo $Revenue.'<br>';
echo $Production.'<br><br>';
}
}else{
echo 'No Record Exists';
}