You can use the as keyword to assign them to a variable as mentioned, or something not many people use.
mysql_fetch_array (not assoc) returns
two arrays - an associative
and a list array. So you can also do
echo $row[0]; // id - remember list arrays start index at 0
echo $row[5]; first status
echo $row[11]; second status
This is extremely useful when you begin to optimize your code for expandability. A very basic example:
$table = 'mytable';
$fields = get_table_names($table); // A function you'd write
$len = count($fields);
$q = "select * from $table where id=1234";
$result = mysql_query($q) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
for ($i=0;$i<$len;$i++) {
echo "<p>Field: " . $fields[$i] . " Value: " . $row[$i] . "</p>\n";
}
}
Any table, any time . . . change the database by adding or rearranging fields, it still works. :-)
How you'd do that in a join? Also a very **basic** example,
$table = 'mytable';
$jointable = 'myjoin';
$fields = get_table_names($table);
$joinfields = get_table_names($jointable);
$len = count($fields)
$total_len = $len + count($joinfields);
$joinfield='Status';
$q = "select $table.*,$jointable.* from $table,$jointable where $table.$joinfield=$jointable.$joinfield and $table.id=1234";
$result = mysql_query($q) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
for ($i=0;$i<$total_len;$i++) {
if ($i<$len) { echo "<p>Field: " . $fields[$i]; }
else { echo "<p>Join Field: " . $joinfields[$i-$len]; }
echo " Value: " . $row[$i] . "</p>\n";
}
}
You can also use array_keys to get field names, but sometimes you need them before actually running a query (table heads.)