Use PHP to Generate HTML table with static Cell Count of MySQL Data

PoedsPaulse

New Member
I have a customer who has asked me to modify one of their scripts to display a table of file names that have been deleted. I am not allowed to modify mysql to mysqli as this is not my site.Rather than putting them all in a line and paginating, he wants columns so that the information can fit on one page. I have tried several methods but none seem to work properlyMethod 1: Displays the correct number of columns, but repeats the same file name in every cell:\[code\]$q = "SELECT `name` FROM `files` WHERE `deleted` = 1";$r = mysql_query($q);$rows = mysql_num_rows($r); $deleted = mysql_fetch_assoc($r);// Build table and iterate through the results $end = $rows; // total # of results $t_rows =ceil($end/5); // number of cells per row $x = 0; $start = 0; echo "<table>"; while($x <= $t_rows){ echo "<tr>"; for($y = 0; $y < 5; $y++, $start++){ if($start <= $end){ echo "<td>".$deleted['name']."</td>"; } } echo "</tr>"; $x++; } echo "</table>";\[/code\]Method 2: Displays the correct number of columns, but on each row it repeats a file name 5x. (Example, Row 1 has the name of the first record 5 times, Row 2, the name of the 2nd file, etc).\[code\]$q = "SELECT `name` FROM `files` WHERE `deleted` = 1";$r = mysql_query($q);$rows = mysql_num_rows($r); // Build table and iterate through the results $end = $rows; // total # of results $t_rows =ceil($end/5); // number of cells per row $x = 0; $start = 0; echo "<table>"; while($x <= $t_rows){ echo "<tr>"; while($deleted = mysql_fetch_assoc($r)){ for($y = 0; $y < 5; $y++, $start++){ if($start <= $end){ echo "<td>".$deleted['name']."</td>"; } } echo "</tr>"; $x++; } } echo "</table>";\[/code\]Thanks in advance
 
Back
Top