I'm having a problem while i'm getting values of `ID` fields from 2 tables in one query. I have same fields as "ID" but these are at different tables.
Tables:
-----------------------------------------
users
--ID
.
.
.
estate_properties
--ID
.
.
.
$sql = mysql_query(select * from users,estate_properties where ...)
while($row = mysql_fetch_assoc($sql)) {
echo $row[ID]; //--> which ID
}
is that possible to use $row[user.ID] or anything else?
Same Fields Problem
Moderator: General Moderators
Re: Same Fields Problem
You could use mysql_fetch_row and reference the desired column as the number in the $row array.
Code: Select all
$sql = mysql_query(select users.ID,estate_properties.ID from users,estate_properties where ...)
while($row = mysql_fetch_row($sql))
{
echo $row[0]; //--> users.ID
echo $row[1]; //--> estate_properties.ID
}
Re: Same Fields Problem
thanks but is there any uses of mysql_fetch_assoc?
Re: Same Fields Problem
I don't think there are. I've Just read the following in the PHP Manual at mysql_fetch_assoc
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you either need to access the result with numeric indices by using mysql_fetch_row() or add alias names. See the example at the mysql_fetch_array() description about aliases.
Re: Same Fields Problem
thanks again
Re: Same Fields Problem
simply assign an alias to one of them, for example estate_properties.id AS estate_id
and then you could have both in the associative array
and then you could have both in the associative array