mysql and mysql_fetch_array / mysql_fetch_assoc
Posted: Mon Jan 20, 2003 11:42 am
I found a problem when converting my select statement. I not sure if this is a bug, feature or how it should work. For the sample here I used the user table in the default mysql database.
When I execute the code below it generates an array with what appears to be no field names. If I use a loop to generate
It display all of the field names... But the code below just returns nothing. What is weird is that when I change the SQL statement from * to user, host then it works perfectly. I know that the data is there it just doesn't work right when using *.
Any ideas? Am I doing something wrong (highest probability)?
BTW, the GetRecordset() is just a wrapper function that just checks for a connection prior to executing the SQL statement and returning the resultset.
//Code
//OUTPUT
User: Host:
User: Host:
User: Host:
When I execute the code below it generates an array with what appears to be no field names. If I use a loop to generate
Code: Select all
foreach ($row as $index=>$value)
echo $index." = ".$value."<br>";Any ideas? Am I doing something wrong (highest probability)?
BTW, the GetRecordset() is just a wrapper function that just checks for a connection prior to executing the SQL statement and returning the resultset.
//Code
Code: Select all
$i=1;
$sql = 'select * from user';
//a simple wrapper function
$rs = GetRecordset($context, $sql);
print "<table>\n";
while (($i <= 200) && ($row = mysql_fetch_array($rs, MYSQL_ASSOC))) {
print "\t<tr>\n";
print "\t\t<td>User: </td>\n";
print "\t\t<td>".$rowї"user"]." </td>\n";
print "\t\t<td>Host: </td>\n";
print "\t\t<td>".$rowї"host"]." </td>\n";
print "\t</tr>\n";
$i++;
}
print "</table>\n";User: Host:
User: Host:
User: Host: