More PHP info
Hello!
I know I haven’t written an entry for a while. I’ve been teaching myself PHP and one thing I could not figure out for the longest time. Well I finally figured it out.
When Querying a MySQL database PHP does not send the results back in an Array!!! You have to convert each row of the results into an array. You will have to use the function:
mysql_fetch_assoc($row)
There are two main ways of completely dumping out the contents of the array. My favorite way I find is the method I will show you. I’ve read in several different places that it is also the fastest as well. Here it is:
while ($row = mysql_fetch_assoc($result)) {
print “Row $rowcount<br />”;
foreach ($row as $key => $val) {
print “$key = $val<br />\n”;
}
print “<br />”;
++$rowcount;
}