note 60962 added to function.mysql-fetch-array
| From: | john at skem9 dot com | Date: | Sat, 21 Jan 2006 12:13:41 +0000 |
| Subject: | note 60962 added to function.mysql-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102206@lists.php.net to get a copy of this message | ||
my main purpose was to show the fetched array into a table, showing the results side by side instead
of underneath each other, and heres what I've come up with.
just change the $display number to however many columns you would like to have, just dont change the
$cols number or you might run into some problems.
<?php
$display = 4;
$cols = 0;
echo "<table>";
while($fetched = mysql_fetch_array($result)){
if($cols == 0){
echo "<tr>\n";
}
// put what you would like to display within each cell here
echo "<td>".$fetched['id']."<br
/>".$fetched['name']."</td>\n";
$cols++;
if($cols == $display){
echo "</tr>\n";
$cols = 0;
}
}
// added the following so it would display the correct html
if($cols != $display && $cols != 0){
$neededtds = $display - $cols;
for($i=0;$i<$neededtds;$i++){
echo "<td></td>\n";
}
echo "</tr></table>";
} else {
echo "</table>";
}
?>
Hopefully this will save some of you a lot of searching.
any kind of improvements on this would be awesome!
----
Server IP: 12.160.245.96
Probable Submitter: 166.82.177.149
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60962
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60962&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60962&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60962&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60962&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60962&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60962&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60962&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60962&report=yes
Search -- http://master.php.net/manage/user-notes.php