Jump to content

Php List Help


driz

Recommended Posts

Hi please take a look at this website: http://hermes.hud.ac.uk/u0558234/mediadrop/The images in the middle are created using UL and LI's the first of each three LI's has a class of "first"My problem is that this list will be displayed using PHP, how can I get it so that when my list is shown, the first li of every 3 li's will have a class of "first"?The list will be shown using a simple echo '<li>$row</li>' variable from an MySQL database.Thanks

Link to comment
Share on other sites

<?php					$host="localhost";					$username="u0559023";					$pass="02dec86";										mysql_connect($host,$username,$pass);					mysql_select_db($username);										$query="SELECT name, work_location  FROM Portfolios, Work WHERE Portfolios.portfolio_id = Work.portfolio_id";					$result=mysql_query($query);					echo "<ul id='home-recent-work'>";										$first = true;									while($row = mysql_fetch_array($result)){													  if ($first)							echo '<li class="first">';						  else							echo '<li>';						  $first = false;										  										echo "<h3>".$row['name']."</h3>";						echo "<a href='profile.php?name=".$row['name']."'><img src='".$row['work_location']."'/></a></li>";										}											echo "</ul>";					mysql_close();										?>

This is what I have so far, it will add the class to the first LI right? How do I get it so it adds it to the first of every 3 LI'sSo I get this effect:

<li class="first"></li><li></li><li></li><li class="first"></li><li></li><li></li><li class="first"></li><li></li><li></li>

Link to comment
Share on other sites

shouldn't that be?
if (!($nr++ % 3)) {	echo '<li class="first">';}  else{	echo '<li>';}

Braces are not needed if there is only a single line of code after the if() statement.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...