Page 1 of 1

formatting based on mysql_num_rows

Posted: Fri Nov 21, 2008 8:56 am
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

Re: formatting based on mysql_num_rows

Posted: Fri Nov 21, 2008 10:33 am
by aceconcepts
Try replacing a single "=" with two i.e. "=="

Code: Select all

 
//replace
if($num_rows = 1)
 
//with
if($num_rows == 1)
 

Re: formatting based on mysql_num_rows

Posted: Fri Nov 21, 2008 10:45 am
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.