formatting based on mysql_num_rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bill1one
Forum Newbie
Posts: 8
Joined: Thu May 24, 2007 2:12 pm

formatting based on mysql_num_rows

Post by bill1one »

I am trying to create a list of urls. I want the first list item to have a space with a larger height than the following items. So height for the first table row would be 3 and the following table rows would be 1. $line is the variable I'm using to define the height. Here is the code I'm currently using:

Code: Select all

 
$num_rows = mysql_num_rows($result);
 
if($num_rows = 1) 
 $line = 3;
else 
 $line = 1;
 
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
 
echo '<tr height="' . $line . '">' .
     '<td bgcolor="#AEBFAE"><img name="spacer" src="../images/clear.gif" border="0" alt="" height="1" width="175"><BR>' .
     '</td>' . 
    '</tr>' .
    '<tr>' .
     '<td bgcolor="#F0EDE3" class="sub"><a href=\"' . $row['url'] . '\">' . $row['name'] . '</a>' .
     '</td>' .
    '</tr>';
}
The result I'm getting is that each list item has a height of 3. Any suggestions on how to correct this would be appreciated.
Thank you.
B
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: formatting based on mysql_num_rows

Post by aceconcepts »

Try replacing a single "=" with two i.e. "=="

Code: Select all

 
//replace
if($num_rows = 1)
 
//with
if($num_rows == 1)
 
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: formatting based on mysql_num_rows

Post by VladSun »

That's why a lot of poeple insist using:

Code: Select all

if(1== $num_rows)
Also, few languages raise up errors when the result is not boolean (i.e. (int)0, or null, or (string)""). I hope that PHP dev team will include this language feature (switched on/off in php.ini) in future.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply