Hey everyone.
I'm doing a join with 3 tables, they all have a field called 'id'.
When I do a query straight to mysql it returns the id fields like
id, id1, id2
This is what I want.
I run the same query in php, and it only get
id
Which has the value of the id2, so its just taking the last id field.
Anyway to make it include the duplicate ones?
Thanks
include duplicate fields on php query
Page 1 of 14 Replies - 785 Views - Last Post: 05 February 2012 - 04:19 AM
Topic Sponsor:
Replies To: include duplicate fields on php query
#2
Re: include duplicate fields on php query
Posted 02 February 2012 - 11:47 PM
please put up your query and let me see and i will try to help.
#3
Re: include duplicate fields on php query
Posted 02 February 2012 - 11:51 PM
SELECT products.*, product_gallery_map.*, image_gallery.* FROM products LEFT JOIN product_gallery_map ON product_gallery_map.productID=products.priKeyID LEFT JOIN image_gallery ON image_gallery.priKeyID=product_gallery_map.galleryID WHERE products.active= '1' ORDER BY products.ordinal
#4
Re: include duplicate fields on php query
Posted 03 February 2012 - 06:55 AM
You can use aliases to set different names for columns and tables. For example:
SELECT p.id AS product_id, gm.id AS gallery_map_id, ig.id AS gallery_id FROM product_table AS p LEFT JOIN product_gallery_map AS gm ON gm.productID = p.id LEFT JOIN image_gallery AS ig ON gm.galleryID = ig.id
#5
Re: include duplicate fields on php query
Posted 05 February 2012 - 04:19 AM
Selecting '*' is something you should avoid for many reasons, and this attribute namespace clash is one of them. There are very few instances where selecting * is both necessary and safe.
Following Atli's advice is your best bet, as it both resolves your problem, and is a good programming technique.
Following Atli's advice is your best bet, as it both resolves your problem, and is a good programming technique.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|