Page 1 of 1

listing results 1 / 0

Posted: Fri Jul 27, 2007 6:36 pm
by spamyboy
Here how it looks now

Code: Select all

$query="select * from lyrics where approved='yes' order by submit_date desc";
$rs=mysql_query($query);
$rcount=0;
while($row=mysql_fetch_array($rs))
{
echo "<li>".$row['title']."</li>";
}
I need to make listing that it would be like:

Code: Select all

echo "<li class='1'>".$row['title']."</li>";
echo "<li class='2>".$row['title']."</li>";
echo "<li class='1>".$row['title']."</li>";
echo "<li class='2'>".$row['title']."</li>";
echo "<li class='1'>".$row['title']."</li>";
I don't realy know how to explain, but hopefuly you understood from exaple result.
How could I do that ?

Posted: Fri Jul 27, 2007 6:54 pm
by vigge89
Use a count variable which is increased by one for every db row, and then check if using modulus 2 against it results in a remainder of zero;

Code: Select all

$query="select * from lyrics where approved='yes' order by submit_date desc";
$rs=mysql_query($query);
$rcount=0;
while($row=mysql_fetch_array($rs))
{
$alternate = ($rcount++ % 2 != 0 ? 1 : 2);
echo "<li class='$alternate'>{$row['title']}</li>";
}

Posted: Fri Jul 27, 2007 7:01 pm
by spamyboy
Thanks.