note 73507 added to function.mysql-fetch-array
| From: | badullaatkaboomdotcom at osu1 dot php dot net | Date: | Mon, 26 Feb 2007 22:15:17 +0000 |
| Subject: | note 73507 added to function.mysql-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123911@lists.php.net to get a copy of this message | ||
Just a real world example from a post below. I found it very useful for creating a table I needed
from hundreds of proprietary colors. I added formatting so HTML source is clean and thought someone
might be able to use or modify as I did.
<?php
// Query
$sql = "select colors_id, colors_type, colors_name, colors_number, R, G, B, colors_wetsample
from products_colors where colors_type = 'Color Canvas' order by colors_number asc limit
40";
$result = mysql_query($sql ,$db);
// Change display for number of columns. Do not change cols as it is needed for counting.
$display = 7;
$cols = 0;
echo " <table border=0 cellpadding=1 cellspacing=0>\n";
while($C = mysql_fetch_array($result)){
if($cols == 0){
echo " <tr>\n";
}
// Display each cell here
echo " <td align=\"center\">\n"
. "\t<table border=0 cellspacing=0 cellpadding=0 width=\"100\"
height=\"100\">\n"
. "\t <tr>\n"
. "\t <td height=\"85\" align=center valign=middle" . " "
. "style=" . "\"" . "background-color: rgb("
. $C['R'] . "," .$C['G'] . "," . $C['B'] .
")\"" . ">\n"
. "\t <span class=\"smcolor\">" . $C['colors_number'] .
"</span>\n"
. "\t </td>\n"
. "\t </tr>\n"
. "\t <tr bgcolor=\"#ffffff\">\n"
. "\t <td align=center valign=middle>\n"
. "\t <span class=\"smcolor\">"
. "<a href=\"javascript:colorPop('../colors.php?colors_type=Color
Canvas&colors_number="
. $C['colors_number'] . "')\"" . ">".
$C['colors_name'] . "</span>\n"
. "\t </td>\n"
."\t </tr>\n"
. "\t</table>\n"
. " </td>\n";
$cols++;
if($cols == $display){
echo " </tr>\n";
$cols = 0;
}
}
// Display the correct HTML
if($cols != $display && $cols != 0){
$neededtds = $display - $cols;
for($i=0;$i<$neededtds;$i++){
echo " <td></td>\n";
}
echo " </tr>\n"
. " </table>\n";
} else {
echo " </table>\n";
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 69.205.247.191
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php
Edit -- https://master.php.net/note/edit/73507
Del: integrated -- https://master.php.net/note/delete/73507/integrated
Del: useless -- https://master.php.net/note/delete/73507/useless
Del: bad code -- https://master.php.net/note/delete/73507/bad+code
Del: spam -- https://master.php.net/note/delete/73507/spam
Del: non-english -- https://master.php.net/note/delete/73507/non-english
Del: in docs -- https://master.php.net/note/delete/73507/in+docs
Del: other reasons-- https://master.php.net/note/delete/73507
Reject -- https://master.php.net/note/reject/73507
Search -- https://master.php.net/manage/user-notes.php