Solved

Multiple tables search

Posted on 2010-09-23
11
393 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
Comment Utility
u could use inner join on the field you want to search
0
 

Author Comment

by:jd_18286
Comment Utility
can i have an example code i have no idea how to do it
0
 
LVL 3

Expert Comment

by:Progressed
Comment Utility
0
 
LVL 1

Expert Comment

by:lovelybabe
Comment Utility
$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
Comment Utility
i was referring for a example code for my script
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:jd_18286
Comment Utility
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
Comment Utility
look at the comment of lovelybabe... that should do it!
0
 

Author Comment

by:jd_18286
Comment Utility
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
Comment Utility
$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
Comment Utility
1052 - Column 'id_lang' in where clause is ambiguous
0
 
LVL 1

Accepted Solution

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

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now