PHP Nested loop - Php

Php with DB

Snippet Code


  
Rate this page :
  [ 0 votes]

<?php $link = mysql_connect("localhost", "root", ""); $res1=mysql_select_db('testfunmin',$link); $query = "SELECT title FROM gamedisp ORDER BY id ASC"; $result = mysql_query($query); $total_records = mysql_num_rows($result); $num_cols = 9; $num_rows = ceil($total_records / $num_cols); $num = 0; echo "<table>n"; for ($rows = 0; $rows < $num_rows; $rows ) { echo "<tr>n"; for ($cols = 0; $cols < $num_cols; $cols ) { if ($num < $total_records) { $titel = mysql_result($result, $num, "title"); $description = mysql_result($result, $num, "descr"); $url = mysql_result($result, $num, "link"); echo "<td><b>".$titel."</b> ".$description."<i><a href="".$url."">Visit here!</a></i><td>n"; } else { echo "<td>ampnbsp;</td>n"; } $num ; } echo "</tr>n"; } echo "</table>n"; ?>

Tags


Ask Questions

Ask Question