Welcome Guest, Not a member yet? Register   Sign In
Check if table is empty
#1

[eluser]Volkof[/eluser]
Hi,

Can anyone guide me on how to check if a returned table is empty?
I used this:

Code:
<?php
   foreach($programmes as $row){
    if(!(empty($row))){
     echo '<a class="'.$row-&gt;programmeID.'" href="/index.php/test/getModules/'. $row-&gt;programmeID.'">';
     echo '<b>'.$row->programmeName.'</b><br/>';
     echo '<br/></a>';  
    }else{
     echo 'No Programmes found!';
    }
   }
  ?&gt;

but the if(!(empty($row))) does not seems to work.
#2

[eluser]Aken[/eluser]
Look into num_rows() or count_all() methods.
#3

[eluser]Rowan Wilson[/eluser]
There are many ways to achieve this.

In your if statement in the foreach loop you don't need the parenthesis around empty().

But otherwise, why not check your result is not empty before trying to loop through it?

e.g.

Code:
if($programmes)
{
foreach($programmes as $row)
{
  //..
}
}
else
{
echo 'No Programmes found!';
}
#4

[eluser]Volkof[/eluser]
Thanks rowstu.

It works now Smile




Theme © iAndrew 2016 - Forum software by © MyBB