Solved

Multiple tables search

Posted on 2010-09-23
11
399 Views
Last Modified: 2012-05-10
Hi, i have this code that makes a search in a table called "contenidos" in the cell "title_contenidos" it works fine but i would like to make it search also in another table and cell:

$not_query_raw = "select * from  contenidos where  title_contenidos like '%" . $_GET['q'] . "%' and id_lang='".$id_lang."'  order by order_contenidos,id_contenidos "    ;

Open in new window


i would like it to also search in the table "proyectos_detalle" and in cell title_proyectos
0
Comment
Question by:jd_18286
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 3

Expert Comment

by:Progressed
ID: 33745425
u could use inner join on the field you want to search
0
 

Author Comment

by:jd_18286
ID: 33745451
can i have an example code i have no idea how to do it
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 1

Expert Comment

by:lovelybabe
ID: 33745543
$raw = "select * from contenidos,contenidos2 where contenidos.id = contenidos2.id and title_contenidos like '%" . $_GET['q'] . "%' and id_lang='".$id_lang."'  order by order_contenidos,id_contenidos "  ;

contenidos2 is the another table
contenidos.id is the example of column name in contenidos,same as in contenidos2.
the value of id is same in two tables.
0
 

Author Comment

by:jd_18286
ID: 33745580
i was referring for a example code for my script
0
 

Author Comment

by:jd_18286
ID: 33745611
but i would like the search to take place also in title_proyectos like '%" . $_GET['q'] . "%'  not only in title_contenidos like '%" . $_GET['q'] . "%'
0
 
LVL 3

Expert Comment

by:Progressed
ID: 33745614
look at the comment of lovelybabe... that should do it!
0
 

Author Comment

by:jd_18286
ID: 33745828
the search should look in 2 tables and 2 colums

1. TABLE= contenidos COLUM = title_contenidos
2. TABLE= proyectos_detalle COLUM = title_proyectos
0
 
LVL 1

Expert Comment

by:lovelybabe
ID: 33745917
$raw = "select * from contenidos,proyectos_detalle where contenidos.title_contenidos = proyectos_detalle.title_proyectos and contenidos.title_contenidos like '%" . $_GET['q'] . "%' and id_lang='".$id_lang."'  order by order_contenidos,id_contenidos "  ;
if still can't works,try to echo it
0
 

Author Comment

by:jd_18286
ID: 33745996
1052 - Column 'id_lang' in where clause is ambiguous
0
 
LVL 1

Accepted Solution

by:
lovelybabe earned 500 total points
ID: 33746113
u need add table name for id_lang,
contenidos.id_lang or proyectos_detalle.id_lang
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question