Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multiple tables search

Posted on 2010-09-23
11
Medium Priority
?
402 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
  • 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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
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 2000 total points
ID: 33746113
u need add table name for id_lang,
contenidos.id_lang or proyectos_detalle.id_lang
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

963 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