if statement not working properly regarding return value- PHP
<p>I tried to solve this problem for several days but still unable to. I'm trying to do an if statement using <code>mysqli_num_rows($result)&gt;0</code> but it wont work properly. This sounds weird. If <code>result&gt;0</code>, it will display records (which is working fine) else no record would be displayed (which is also working fine) but the table keeps showing. I don't know why(the table not suppose to appear if result returned empty).The other related problem is, when there is no record, 3 value seems to appear  (no image value under column picture, date under column <code>Dat Reg</code>, delete under column Terminate Membership). Any help would be appreciated.I can't get "no image value", "date" and "delete" to go away when result return empty. I'm trying to make the entire table not to appear so that the columns (would also not show but it can't work).</p>

<p><strong>userpage.php</strong></p>

<pre><code>&lt;p align="left"&gt;A. YOUR RECORDS &lt;/p&gt;
&lt;p align="left"&gt;
&lt;?php
echo "&lt;tr&gt;&lt;td&gt;&lt;/tr&gt;&lt;/td&gt;";
if(mysqli_num_rows($result)&gt;0){
echo "&lt;table cellpadding=10 border=0 id='secondtable'&gt;";
echo "&lt;tr&gt;&lt;td bgcolor=#698C00 class='white'&gt;"."Membership"."&lt;/td&gt;".
"&lt;td bgcolor=#698C00 class='white'&gt;"."Title"."&lt;/td&gt;".
"&lt;td bgcolor=#698C00 class='white'&gt;"."Location"."&lt;/td&gt;".
"&lt;td bgcolor=#698C00 class='white'&gt;"."Phone"."&lt;/td&gt;".
"&lt;td bgcolor=#698C00 class='white'&gt;"."Picture"."&lt;/td&gt;".
"&lt;td bgcolor=#698C00 class='white'&gt;"."Date Reg"."&lt;/td&gt;".
"&lt;td bgcolor=#698C00 class='white'&gt;"."Terminate Membership?"."&lt;/td&gt;&lt;/tr&gt;";
if(mysqli_num_rows($result)&gt;0){
while( $row = $result-&gt;fetch_array(MYSQLI_ASSOC)){
$showdateua=$row['dateua'];
$showdateua=date('d-m-Y',strtotime($showdateua));
echo "&lt;tr&gt;&lt;td bgcolor=#DCDCDC&gt;".$_SESSION['Membership']=$row['Membership'].
"&lt;/td&gt;&lt;td bgcolor=#DCDCDC&gt;".$_SESSION['Title']=$row['Title'].
"&lt;/td&gt;&lt;td bgcolor=#DCDCDC&gt;".$_SESSION['location']=$row['location'].
"&lt;/td&gt;&lt;td bgcolor=#DCDCDC&gt;".$_SESSION['adphone']=$row['adphone'].
"&lt;/td&gt;&lt;td bgcolor=#DCDCDC&gt;".
'&lt;img src="'.$_SESSION['image1']=$row['image1'].'"alt="No image"style="width:100px;height:100px;"/&gt;'.
"&lt;/td&gt;&lt;td bgcolor=#DCDCDC&gt;".$_SESSION['dateua']=$showdateua.
"&lt;/td&gt;&lt;td bgcolor=#DCDCDC&gt;"."&lt;a href=\"rundelup.php?idadv=".$row['idadv']."\"&gt;"."Delete"."&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;";
}
}
echo "&lt;/table&gt;";}
else
{
if(mysqli_num_rows($result)===0)
{echo "No records";}
}?&gt;
&lt;?php
if(isset($_SESSION['id'])){
if (isset($result)){
if(mysqli_num_rows($result)&gt;0){
echo "&lt;table&gt;";
$page=(int)$page;
if($page&gt;$tpages)
{$page=$tpages;}
if($page&lt;1)
{$page=1;
}
if($page==1){
echo "";}
else
{
//go to first page 
echo "&lt;tr&gt;&lt;td&gt;&lt;a href='?page=1'class='button'&gt;FIRST&lt;/a&gt;&lt;/td&gt;";
}
if($page&gt;1)
{
//go to previous page to show previous 3 items. 
echo "&lt;td&gt;&lt;a href='?page=".($page-1)."'class='button'&gt;&lt;&lt;&lt;/a&gt;&lt;/td&gt;";
}
echo "&lt;ul class='page'&gt;";
for($i=max($page-4,1);$i&lt;=max(1,min($tpages,$page+4));$i++)
{
if($i==$page){
echo "&lt;td&gt;&lt;class='current'&gt;".$i."&lt;/td&gt;";
}
else{
echo "&lt;td&gt;&lt;a href='?page=".$i."'&gt;".$i."&lt;/a&gt;&lt;/td&gt;";}
//echo "&lt;tr&gt;&lt;td&gt;&lt;a href=useradacc.php?page=".$i."&gt;".$i."&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;";
}
echo "&lt;/ul&gt;";
if($page!=$tpages)
{
//go to next page to show next 3 items. 
echo "&lt;td&gt;&lt;a href='?page=".($page+1)."'class='button'&gt;&gt;&gt;&lt;/a&gt;&lt;/td&gt;";
}
if($page==$tpages)
{
    echo "";}
    else{
//go to last page 
echo "&lt;td&gt;&lt;a href='?page=".($page=$tpages)."'class='button'&gt;LAST&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;";
}
echo "&lt;/table&gt;";
}
}}
else
{echo "Insert record";
}
?&gt;
</code></pre>

<p><strong>include file (run.php)</strong></p>

<pre><code>&lt;?php
if(isset($conn)){
$id = $_SESSION['id'];
//pagination calculation
$reclimit=3;
if(isset($_GET['page'])){
$page=$_GET['page'];}
else
{
$page=1;
}
$start=(($page-1)*$reclimit);
$advert = "SELECT u.*,ua.* FROM uskkk u LEFT JOIN uaddd ua ON  u.id=ua.id
WHERE u.id='".$id."'";
$result=$conn-&gt;query($advert);
$total=$result-&gt;num_rows;
$tpages=ceil($total/$reclimit);
//pagination script ends here
$advert = "SELECT u.*,ua.* FROM uskkk u LEFT JOIN uaddd ua ON  u.id=ua.id
WHERE u.id='".$id."'ORDER BY dateua DESC LIMIT $start,$reclimit";
$statement = $conn-&gt;prepare($advert);
$statement-&gt;execute();
$result = $statement-&gt;get_result(); }
if ($conn-&gt;connect_error){
die("Connection failed: ".$conn-&gt;connect_error);
} 
?&gt;
</code></pre>