Re: Failed to query correctly.
| From: | Dobromir Velev | Date: | Tue, 04 Dec 2001 08:19:23 +0000 |
| Subject: | Re: Failed to query correctly. | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-14800@lists.php.net to get a copy of this message | ||
Hi,
The code looks fine to me - it will output all records in the selected table.
I assume that you want to display the field names as a first row. If this is the case you could use
something like this
$query="SELECT * from $tbl";
$result=mysql_db_query($db,$query) or mysql_die();
echo "<table>";
while ($line = mysql_fetch_array($result,MYSQL_ASSOC)) {
if (!$first){
echo "<tr>";
while(list($col_name, $col_value) = each($line)) {
print "\t\t<td><p align=center>$col_name</p></td>\n";
}
echo "</tr>";
$first=1;
}
echo "<tr>";
while(list($col_name, $col_value) = each($line)) {
print "\t\t<td><p align=center>$col_value</p></td>\n";
}
echo "</tr>";
}
echo "</table>";
Hope this helps
Dobromir Velev
Web Developer
http://www.websitepulse.com/
-----Original Message-----
From: Denny <denow@yahoo.com>
To: php-db@lists.php.net <php-db@lists.php.net>
Date: Tuesday, December 04, 2001 09:14
Subject: [PHP-DB] Failed to query correctly.
Hi,
I got this problem when i tried to do a sql query and print the ouput. But the script below always
failed to return the first row of
the records. But i do a manual query, i got the results i wanted.
Thanks,
Denny
$query="SELECT * from $tbl ";
$result=mysql_query($query);
while ($line = mysql_fetch_row($result)) {
while(list($col_name, $col_value) = each($line)) {
print "\t\t<td><p align=center>$col_value</p></td>\n";
}
}