polaries Posted April 25, 2017 Share Posted April 25, 2017 In example : i have a query with "select * ... " that returns the field 'name' from products and the field 'name' from manufacturers. when i do $row['name'] how i distinguish the name from products and the name from manufacturers? Thanks. Link to comment Share on other sites More sharing options...
bellini13 Posted April 25, 2017 Share Posted April 25, 2017 name the tables (from product_lang pl, from manufacturers m), and then you should be able to use pl.name or m.name) otherwise don't use select *, but rather select specific column names from each table that you need (this is the proper way so you are not querying for data that you do not use). then give the name columns an alias (select name as product_name), and then use $row['product_name'] Link to comment Share on other sites More sharing options...
polaries Posted April 25, 2017 Author Share Posted April 25, 2017 (edited) name the tables (from product_lang pl, from manufacturers m), and then you should be able to use pl.name or m.name) otherwise don't use select *, but rather select specific column names from each table that you need (this is the proper way so you are not querying for data that you do not use). then give the name columns an alias (select name as product_name), and then use $row['product_name'] that´s i do,i named tables with synonim but i can´t use $row['pl.name'] or $row['m.name'] this not works,the solution is use * like this --> "select *,pl.name as pname,m.name as mname .... " and then you can do $row['pname'] and $row['mname'].is a ugly solution,but it works. I must say that i use DbQuery. $sql = new DbQuery(); $sql->select('*,mn.name manName,pl.name prodName'); Thanks by your answer. Edited April 25, 2017 by polaries (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted April 25, 2017 Share Posted April 25, 2017 in the future, you could print_r the result array returned from executing the query, and see what the array index names are. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now