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
spamyboy
Forum Contributor
Posts: 266 Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius
Post
by spamyboy » Fri Jul 27, 2007 6:36 pm
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 ?
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Fri Jul 27, 2007 6:54 pm
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>";
}
spamyboy
Forum Contributor
Posts: 266 Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius
Post
by spamyboy » Fri Jul 27, 2007 7:01 pm
Thanks.