MySQL & numeric keys - is this a valid query?
Posted: Sat Oct 22, 2005 3:40 pm
Assume the following fictitious query:
With respect to echoing out each element, I was kind of surprised that this seemed to work by calling a numeric reference, as opposed to the normal method, being "$dbResult['firstName']". I can't recall coming across this in anything I've read thus far (or maybe it went over my head at the time) and was wondering if indeed it was a valid way to loop through the data. The manual says:
Are there advantages/disadvantages to using one over the other?
Code: Select all
$result = mysql_query("SELECT firstName, lastName, FROM people");
echo "<table>";
while($dbResult = mysql_fetch_array($result)) {
echo "<tr><td>".$dbResult['0']."</td>";
echo "<td>".$dbResult['1']."</td></tr>";
}
echo "</table>";so I'm assuming this is an instance of "both"?mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both
Are there advantages/disadvantages to using one over the other?