Jump to content

How to get a row from database with same field name?


polaries

Recommended Posts

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

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

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 by polaries (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...