ok, am building a little php app for uni (this probably seems like a very noobish question ,but I only started php about a month ago )
Problem is, I am selecting data from a mysql database, and the query left-joins two tables. now, I have the same column-name in each table (u_id). When i try to spit out the associated value of u_id after putting the query result into an associated array, it gives me the value of the second u_id and not the first, which is not what I want.
How do I tell the array to select the first u_id column and not the second?
thanks,
Henry
mysql_assoc_array( question.(probably very simple)
Moderator: General Moderators
Query aliases?
If your ON statement is on the id. I don't have any idea. You may need to rethink you database/query.
Code: Select all
$sql = "SELECT a.u_id, a.field2, b.field2
FROM users a
LEFT JOIN some_table b
ON a.field2 = b.field2";- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you can either get specific about what you select from the tables (sort of), or not use the associative fetch. A numeric fetch will have all fields in order of selection. You can retrieve the names using other database function calls.
The first can also be done using a RIGHT JOIN, where you place the original first table on the right, instead of the left.
The first can also be done using a RIGHT JOIN, where you place the original first table on the right, instead of the left.