I have a MySQL result set
$fields_num = mysql_num_fields($result);
I would like to assign all of these results PHP variables that I can use on the page. What's the easiest way?
Thanks!
I have a MySQL result set
$fields_num = mysql_num_fields($result);
I would like to assign all of these results PHP variables that I can use on the page. What's the easiest way?
Thanks!
$row = mysql_fetch_assoc($result);
Access via $row["name"]
$row = mysql_fetch_array($result);
Access via $row[0] and $row["name"]
Complete example...
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result)){
echo $row[0];echo $row["name"];
}
Will print "id" and "name".
Try mysql_fetch_array which return results as an array with column name as associate key
$row = mysql_fetch_array($result, MYSQL_ASSOC);
/* $row will be an array */
/* and the column wil be the associate key */
OR
you can use mysql_fetch_field, which provide even more information