Very perceptive 🙂
In PHP, associative arrays (name indexed arrays, sometimes called a hash) are the same as numerically indexed arrays.
In a "normal" array (numerically indexed) you access the values stored in the array with a index number.
$array[0]
$array[23]
etc
An associative array is a "normal" numerically indexed array with an additional index for each value. This additional index is the "name" of the position in the array. Therefore, you can access the same value in an associative array two ways.
Let's say at the beginning of your script you have:
$array[foo] = 'bar';
$array[funky] = 'monkey';
The first value of the array, in this case the string 'bar', can be accessed using $array[foo] AND $array[0]. Remember that arrays start at 0 in PHP (and many other languages).
Likewise, 'monkey', the 2nd value, can be accessed using $array[funky] AND $array[1];
When you call '$row = mysql_fetch_row( $result )', PHP creates a new array (or resets an old array) called $row, which has a single index for each value. Since our select statement in question has a single returned field, $row contains a single value at index 0.
You must access the single value with $row[0].
When you call '$row = mysql_fetch_array( $result )', PHP creates an array called $row, which has 2 indexes for each value: a numerical index and an alphanumeric index which is the field name.
In this case, you can access the single returned value with $row[0] AND $row[total].
Using mysql_fetch_array() is nice because you don't have to know the order of the field in the result.
If you do "SELECT name, age FROM Users", you know that $row[0] contains the name field nd $row[1] contains the age field.
But, suppose you did not create the table or the database. You may know the names of the fields, but not necessarily the order that they were added to the table. So, if you do "SELECT * FROM Users", name could be the first field, last field, or anywhere in between.
But, if you use mysql_fetch_array(), you KNOW that you can access the name field as $row[name] even if you don't know what numeric index is also assigned to that field.
Does this help?
Let me know if you have any further questions.
-Rich