Select multiple fields with same name - array problem

I have a select statement for example:


SELECT table1.id, name, table2.id, branch
FROM table1
INNER JOIN table2
ON userid = table2.id
WHERE table1.id = 30;

So, this is just an example. The problem I’m having is now doing this:


$row = mysql_fetch_array($result)

Since there are two IDs being selected, my array looks like this:

$row['id'] = table2.id
$row['name'] = name
$row['branch'] = branch

There isn’t a second id item in the array and instead the first is being overwritten by the second value.

What am I doing wrong?

Edit: Actually the array looks more like this:


Array
(
    [0] => table1.id
    [id] => table2.id
    [1] => name
    [name] => name
    [2] => table2.id
    [3] => branch
    [branch] => branch
)

The best way is to use an alias


SELECT
table_name.field_name AS alias_name

To get more then one record from a result set you need to use a loop.


while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $the_result_set[] = $row;
}

Right on, that fixed it, thanks.

Also, I didn’t use a loop just because the select statement is only selecting one row.