Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_fetch_object & multi-table search

Status
Not open for further replies.

barryp

Programmer
Jan 30, 2002
48
GB
I'm sure I come across the answer - but can't find it when I really need it !

I make an sql query like

$query = "SELECT * FROM `product` as p, `productlanguage` as p1, `productlanguage` as p2 WHERE (p.guid=p1.d_id and p1.lang_id='de') and (p.guid=p2.d_id and p2.lang_id='en')";
$result = mysql_query($query) or die("Invalid Query - $query");

while($row = mysql_fetch_object($result)) {
}


QUESTION: the field 'description' appears twice in the result (since I'm getting two rows from the same table)
How can I extract them both ?

$row->description[1] - WRONG !

Help much appreciated
 
One way is to use MySQL's "AS" operator in your query:

SELECT field1 AS foo, field2 AS bar FROM mytable

If you have a lot of fields, it can make for an ugly query, though.

Another way is to use mysql_fetch_array() and refer to the returned columns by their numerical array indeces. This reduces readability. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top