Question about mysql_fetch_row in php?

Felipe A

New member
Does anyone have any idea why the following code outputs

"This is the result: "

$sql = "SELECT MAX(patient_id) AS 'max_pat_id' FROM patient_information;";

$result = mysql_query($sql);
while ($row = mysql_fetch_row($result)) {
echo "This is the result: " . $row['max_pat_id'] . "<br>";
}
?>

Where as if I were to put in

$sql = "SELECT MAX(patient_id) AS 'max_pat_id' FROM patient_information;";

$result = mysql_query($sql);
while ($row = mysql_fetch_row($result)) {
echo "This is the result: " . $row[0] . "<br>";
}
?>

I then get "This is the result: 1" (1 can be any number obviously)

I am not sure why but for some reason I can't reference the column I want in row via the column label. I am new to both php and sql but I still don't understand why this wouldn't work.
 
Back
Top