PHP while loop and if statement : <p>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 <code>else</code> and <code>echo</code> 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</p>

<pre><code>$recID = '55';

$results2 = $db2-&gt;query("SELECT * FROM Movies WHERE TMDBid = '$recID'");

while($row2 = $results2-&gt;fetchArray()){

if(!empty($row2['id'])){

$Runtime = $row2['Runtime'];
$Budget = $row2['Budget'];
$Revenue = $row2['Revenue'];
$Production = $row2['Production'];

echo $Runtime.'&lt;br&gt;';
echo $Budget.'&lt;br&gt;';
echo $Revenue.'&lt;br&gt;';
echo $Production.'&lt;br&gt;&lt;br&gt;';    

}else{

echo 'No Record Exists';

}
  }
</code></pre>

<p>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.</p>

<pre><code>$recID = '55';

$results2 = $db2-&gt;query("SELECT * FROM Movies WHERE TMDBid = '$recID'");

if($results2-&gt;fetchArray() !== false){

while($row2 = $results2-&gt;fetchArray()){

$Runtime = $row2['Runtime'];
$Budget = $row2['Budget'];
$Revenue = $row2['Revenue'];
$Production = $row2['Production'];

echo $Runtime.'&lt;br&gt;';
echo $Budget.'&lt;br&gt;';
echo $Revenue.'&lt;br&gt;';
echo $Production.'&lt;br&gt;&lt;br&gt;';    

}

}else{

echo 'No Record Exists';

}
</code></pre>
