...

View Full Version : if & else problem



tanhaha_how
02-28-2007, 05:11 PM
hi,i hav a problem here...

if lets say i hav a query:


$query1= "select count(*) AS i from tblpatient";


then i wan to count how many records there:


<?php if ($row1["i"] >= 1){ ?>
<tr>
-----
</tr>

<?php }else {?>
<tr>
<td height="60" colspan="16"><center>NO RECORDS</center></td>
</tr>

<?php }?>


but it still cannot show NO RECORDS whenever there is no record...
izzit if ($row1["i"] >= 1){ sth wrong?????

Fumigator
02-28-2007, 05:44 PM
The code you posted looks ok, so the problem must be in the code you didn't post-- the "fetch" statement, etc.

JohnDubya
02-28-2007, 05:53 PM
then i wan to count how many records there:


<?php if ($row1["i"] >= 1){ ?>
<tr>
-----
</tr>

<?php }else {?>
<tr>
<td height="60" colspan="16"><center>NO RECORDS</center></td>
</tr>

<?php }?>



Easiest way to count how many rows were retrieved is to use mysql_num_rows(), like so:


$query1= "select count(*) AS i from tblpatient";

$count = mysql_num_rows($query1);

if ($count < 1) {
//echo "no rows were found"
} else {
//echo the rows that were found
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum