Displaying database records in unordered list format

Jimmy Wales Reply 09:52
Just keep a counter, increment it in the loop, and if it's an odd number set class to odd, if even set class to even. 
$result  = "";
$count = -1;

while ( $row = mysql_fetch_assoc( $query) ) {
  $class = $count++ % 2 === 0 ? "even" : "odd" ;
  $href  = $row["url"];
  $text  = $row["name"];
  $output .= "<li class='{$class}'><a href='foo?id={$href}'>{$name}</a></li>";
}

echo "<ul>{$result}</ul>";

Related Posts

PHP 8843334090624570929
Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us