Mysql and mysql_fetch_array
| From: | Darko | Date: | Tue, 09 Oct 2001 18:27:07 +0000 |
| Subject: | Mysql and mysql_fetch_array | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-9771@lists.php.net to get a copy of this message | ||
Hello.
This script gives me every data twice in print if I have database with
names on database output look like this:
John John Doe Doe Phone Phone 1234 1234
Why?
<?php
$link = mysql_connect("mysql_host", "mysql_login",
"mysql_password")
or die ("Could not connect");
print ("Connected successfully");
mysql_select_db ("my_database")
or die ("Could not select database");
$query = "SELECT * FROM my_table";
$result = mysql_query ($query)
or die ("Query failed");
// printing HTML result
print "<table>\n";
while($line = mysql_fetch_array($result)){
print "\t<tr>\n";
while(list($col_name, $col_value) = each($line)){
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>