![]() |
Search query multiple tables? (PHP, MySQL)
I'm working on a php project. i have a create a search product page. its contain multi table and working fine but exact problem is both table have some same column names i can't get the first table column value
Database Structure //I can't change must i've to create a script for getting result tbl_products:- rn //i want this value because i'm using as a product id imagename tbl_productsdetail rn //i don't wana this value pn //value coming from tbl_products rn column name description Code:
$apshmquery="select p.*, pd.* from tbl_products p, tbl_productsdetail pd where p.code like '%" . $apshmreqcode . "%' or pd.name like '%" . $apshmreqq . "%' or pd.description like '%" . $apshmreqq . "%' and p.rn=pd.pn ";have any good solution?? Thank's in advance :) |
You can use the
AS keyword for that.sql Code:
Please let me know if that makes sense. If not, I will explain much better :-) ! |
Quote:
|
If you have conflicting columns then you will, unfortunately, need to specify them individually as in the code example.
To take your code as the example this time, you would have to specify explicitly that you would like the id from the tbl_products table, with your supplied alias, p. You would specify this by adding the following to your SELECT statement:sql Code:
Which, excluding your conditionals at the end of your MySQL statement above, would now be like so: sql Code:
All your data is still returned, but the ID you require is now stored in rn_id, because rn_id is unique, whereas id is not unique to that particular table, and therefore overwritten.So then to get the value you would do: php Code:
|
Quote:
Thank dude its working fine but i'm not getting search query result 100% Code:
select p.*, pd.*, p.rn as p_rn from tbl_products p, tbl_productsdetail pd where p.rn=pd.pn and p.code like '%2001%' or pd.name like '%a%' or pd.description like '%a%' |
What do you mean by not 100%? What appears to not be working?
|
Thank's
Its Working Fine Now :) |
| All times are GMT. The time now is 03:25 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0