473,546 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple Table Search

384 Contributor
I have a basic search function working with PHP and mysql, can anyone help me to make a function that takes a single search criteria and searches multiple tables and gives the different results back to the user??
Mar 4 '09 #1
12 2253
TheServant
1,168 Recognized Expert Top Contributor
I'm sure we can help. We however will not write it for you, but rather help you fix your own code. Please post the code in question and any relavent other snippets. Also include a detailed description of what is happening, and what should be happening that is not.
Mar 4 '09 #2
pradeepjain
563 Contributor
@ziycon
Are u clear on to which tables to search or search all tables in a DB is needed
Mar 4 '09 #3
Markus
6,050 Recognized Expert Expert
You could use a JOIN, but I'm not quite sure on the specifics of your problem. Elaborate?
Mar 4 '09 #4
numberwhun
3,509 Recognized Expert Moderator Specialist
So let me get this right, you have a search in mysql that you want to perform over a bunch of tables.

Why not put the names of the tables into an array and then cycle through the array, performing the search for each table?

Regards,

Jeff
Mar 4 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
MySQL entry for multiple table selects: MySQL manual - SELECT > JOIN
Mar 5 '09 #6
ziycon
384 Contributor
Sorry for not getting back sooner. I have this code below for the search so far and it works fine, but it's very crude.
I haven't had much exposure to joins and inner selects which I'm assuming I'm going to need to use to solve my issue. I currently have four table in the database and the below code is just searching the title of these records based on the inputted value and the table selected from the drop down list on the page.
I want the user to just enter a word or phrase and then the search to be run based on the value over the four tables through both the title and body of each record and out put them in a percentage relevant order.
All the fields in the query are the same across all four tables.
Expand|Select|Wrap|Line Numbers
  1. function display_details($q,$table) {
  2.   $link = '';
  3.  
  4.   $sql = mysql_query("SELECT id,title,body,date,time FROM ".$table." WHERE title LIKE '%".$q."%' ORDER BY date DESC, time DESC");
  5.   while($row = mysql_fetch_array($sql))
  6.   {
  7.     $link_name = preg_replace('#[^a-zA-Z0-9]+#','-',$row['title']);
  8.     echo '<div class="search_results_wrapper">
  9.         <div class="search_results_link_name"><div class="search_results"><a href="'.$link.$row['id'].'-'.$link_name.'.htm">'.$row['title'].'</a></div></div>
  10.         <div class="search_datetime">'.strftime("%b %d, %Y", strtotime($row['date'])).' at '.wordwrap(substr($row['time'],0,5)).'</div>
  11.         <div class="search_results_body">'.add_dots(format_article_2($row['body']),'|',150).'</div>
  12.         <div class="search_results_url">'.$link.$row['id'].'-'.$link_name.'.htm</div>
  13.     </div>
  14. ';
  15.   }
  16. }
Mar 6 '09 #7
ziycon
384 Contributor
Can anyone advise on this?
Mar 19 '09 #8
Markus
6,050 Recognized Expert Expert
Is the seperation of the tables really necessary? If they're holding the same type of data, it makes sense to have it all in one table.

However, you can do multiple joins like so:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT tb1.*, tbl2.*, tbl3.* FROM `table_1` AS tbl1
  3. LEFT JOIN `table_2` AS tbl2
  4.  ON tbl1.id = tbl2.id
  5. LEFT JOIN `table_3` AS tbl3
  6.  ON tbl2.p_type = tbl3.p_type
  7.  
  8.  
Something like that.
Mar 19 '09 #9
ziycon
384 Contributor
There is other fields in these tables relevent to each section hence why they are not in the one table, i'll try the inner joins and let you know, thanks.
Mar 19 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
9968
by: Steven An | last post by:
Howdy, I need to write an update query with multiple aggregate functions. Here is an example: UPDATE t SET t.a = ( select avg(f.q) from dbo.foo f where f.p = t.y ), t.b = ( select sum(f.q) from dbo.foo f where f.p = t.y ) FROM dbo.test t
11
5270
by: Mike | last post by:
Looking to find any information on how to properly configure multiple instances of DB2. This is on Win2k db2 ver 7.2. I am basically looking for information on how the multiple instance settings should configured to work, how memory is shared or not, etc. I can not seem to find any good links to this information. Thanks, Mike
4
3741
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure and username, password etc will be exactly the same for each server, the only thing that will change is the server name. Idealy I would like to get...
5
4172
by: JP SIngh | last post by:
Hi All This is a complicated one, not for the faint hearted :) :) :) Please help if you can how to achieve this search. We have a freetext search entry box to allow users to search the database. I am searching two tables. SELECT TapeRecords.Id, TapeRecords.ItemTitle, TapeRecords.SourceRef,
5
11926
by: mforema | last post by:
Hi Everyone, I want to search records by typing in multiple keywords. I currently have a search form. It has a combo box, text box, Search command button, and a subform. The combo box lists the names of the fields found in my subform. The search form is supposed to allow a user to choose which field he/she wants to search by and then type a...
0
2066
by: redpears007 | last post by:
Morning all! :) I have a database with multiple linked tables. I have created a search form with one txt box, for entering search criteria, and a listbox for each of the tables to isplay the results from that table. These list boxes work well, but they are now cluttering the screen.
3
2699
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only allows me to filter based on variables in a single table. I would like to have a search form where I can select multiple variables (from various...
1
4142
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only allows me to filter based on variables in a single table. I would like to have a search form where I can select multiple variables (from various...
1
1319
by: Kevin | last post by:
Hello, I'm doing a school project and I'm supposed to be able to track campgrounds and their amenities. Here is some of the information I'm supposed to store: CAMPGROUND Number of Sites Number Summer Season End Date Summer Season Start Date Reservations Accepted Y/N
2
2766
by: helplakshmi | last post by:
Hi All, I am new to php. The form that i am designing has few input input fields with submit and reset button. The functionality of submit and reset are working properly till now. My form <form name="search" id="search" action= "search.php" method = "post" onreset="formReset(this);return false;"> <table cellspacing="1"...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7794
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.