i have a query:
$sql_enquiry = "select fname,lname from tbl_enquiry order by eqid asc";
$result = mysql_query($sql_enquiry,$my_conn);
$num_rows = mysql_num_rows($result);
i want to loop the results like this:
---------------------------
Result 1 | Result 2 | Result 3 |
---------------------------
Result 4 | Result 5 | Result 6 |
---------------------------
Result 7 | Result 8 | Result 9 |
---------------------------
Result 10 | Result 11 | Result 12
---------------------------
HOW CAN I DO THIS
loop question
Moderator: General Moderators
Code: Select all
$result = Array();
$x = 0;
while ($row = mysql_fetch_array($sql_enquiry)) {
$result[$x] = $row;
$x++;
}
echo $result[$x][0];-
pootergeist
- Forum Contributor
- Posts: 273
- Joined: Thu Feb 27, 2003 7:22 am
- Location: UK
Code: Select all
echo '<table border="1">';
$tmp_cnt = 0;
$per_row = 3;
while($row = mysql_fetch_array($result))
{
echo (($tmp_cnt %$per_row == 0) ? '<tr>' : '').
' <td>' .$row['fname']. ' ' .$row['lname']. '</td>'
.((++$tmp_cnt %$per_row == 0) ? '</tr>' : '');
}
echo ($tmp_cnt %$per_row !== 0)
? '<td colspan="' .($per_row - ($tmp_cnt % $per_row)). '">& nbsp;</td></tr>'
: '';
echo '</table>';