473,465 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help with SQL search through multiple tables

LRW
Well, I have another question that's hard to ask, so I may end up over
explaining the question.
I have about 40 tables, all with a similar column structure. I want to be
able to search through every table for a keyword.
Is there a way to do that using, an array or next or something.

So like, all the table, say tbl_1, tbl_2, tbl_3 etc have let's say 3
columns. id, name, note for example. And I want to seach all 40 tables in
the name column for %x%.

If someone can just point me to a Web site that has tips or whatnot, that'd
be cool. If I know where to look I can teach myself...just need a direction.
=)

Thanks for any feedback!!
Liam
Jul 17 '05 #1
5 8986
LRW wrote:
Well, I have another question that's hard to ask, so I may end up over
explaining the question.
I have about 40 tables, all with a similar column structure. I want to be
able to search through every table for a keyword.
Is there a way to do that using, an array or next or something.

So like, all the table, say tbl_1, tbl_2, tbl_3 etc have let's say 3
columns. id, name, note for example. And I want to seach all 40 tables in
the name column for %x%.

If someone can just point me to a Web site that has tips or whatnot, that'd
be cool. If I know where to look I can teach myself...just need a direction.
=)


You need to make as many quieries as there are tables you want to search, of
course you could make a join, but that depends on how things are related to
eachother.

Assume you have a array with the names of all the talbes you need to search,
we call it $tables. Another arrya where you save the results, $found.

for(i=0;i<count($tables);i++) {
$query="SELECT * FROM " . $table[i] . " WHERE name LIKE '%x%'";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)) {
array_push($found,$row);
}
}

Now you have all the result rows stored in $found, of course you can
send/process the $row in the while loop.
Follow up has been set to proper newsgroup, alt.php.sql

//Aho
Jul 17 '05 #2
LRW
"J.O. Aho" <us**@example.net> wrote in message
news:bu************@ID-130698.news.uni-berlin.de...
You need to make as many quieries as there are tables you want to search, of course you could make a join, but that depends on how things are related to eachother.

Assume you have a array with the names of all the talbes you need to search, we call it $tables. Another arrya where you save the results, $found.

for(i=0;i<count($tables);i++) {
$query="SELECT * FROM " . $table[i] . " WHERE name LIKE '%x%'";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)) {
array_push($found,$row);
}
}

Now you have all the result rows stored in $found, of course you can
send/process the $row in the while loop.
Follow up has been set to proper newsgroup, alt.php.sql


Cripes! My ISP doesn't have alt.php.sql. That'd be a perfect group for a lot
of my questions! =/

So $found wouldn't have to exist before we query, right?
I do currently have another table that has all the table names in it.
eg: (but not exactly like this,)
40 tables with the following columns: id, tbl_id, name, note
Then a table (tbl_listing) with these columns: tbl_id, tbl_name
Make sense? Each row in all 40 tables has a tbl_id number that corresponds
to the table it's in, and the table tbl_listing has in each row the that
table number and its name.

So...that doesn't matter, does it? What would $table contain? The names of
all 40 tables comma separated?

Thanks for replying!
Liam
Jul 17 '05 #3
LRW wrote:
So $found wouldn't have to exist before we query, right?
I do currently have another table that has all the table names in it.
eg: (but not exactly like this,)
40 tables with the following columns: id, tbl_id, name, note
Then a table (tbl_listing) with these columns: tbl_id, tbl_name
Make sense? Each row in all 40 tables has a tbl_id number that corresponds
to the table it's in, and the table tbl_listing has in each row the that
table number and its name.
To be on the safe side, it's always best to create an empty arrya first
$found=array();

When you save stuff to the $found array, you should tell from which table the
result comes from, I leave it up to you how you want to make that. As using
the *, you will get all the columns of the database line, regadles how they
look like.

So...that doesn't matter, does it? What would $table contain? The names of
all 40 tables comma separated?


A normal array of strings,

$table=array("array1","array2","arrayA",...);

With help of the array you don't have to number the tables in a special way
and you can select the order in which to seach the tables and of course, you
can jump over a table if you want, then just don't include it in the array.

//Aho
Jul 17 '05 #4
RP

"LRW" <dr***@NOSPAHMcelticbear.com> schreef in bericht
news:hSfOb.88123$na.47077@attbi_s04...
Well, I have another question that's hard to ask, so I may end up over
explaining the question.
I have about 40 tables, all with a similar column structure. I want to be
able to search through every table for a keyword.
Is there a way to do that using, an array or next or something.

So like, all the table, say tbl_1, tbl_2, tbl_3 etc have let's say 3
columns. id, name, note for example. And I want to seach all 40 tables in
the name column for %x%.

If someone can just point me to a Web site that has tips or whatnot, that'd be cool. If I know where to look I can teach myself...just need a direction. =)

Thanks for any feedback!!
Liam

depending on the database (or mysql version :o) you use, UNION is the answer
I think:
http://www.mysql.com/doc/en/UNION.html

RP
Jul 17 '05 #5
damn :), is it that hard?

http://groups.google.com/groups?q=al...oe=UTF-8&hl=en

With google you can access virtually any newsgroup(+archive).

Best Regards,

Lucas

"LRW" <dr***@NOSPAHMcelticbear.com> schrieb im Newsbeitrag
news:Q%gOb.87151$8H.130499@attbi_s03...
"J.O. Aho" <us**@example.net> wrote in message
news:bu************@ID-130698.news.uni-berlin.de...
You need to make as many quieries as there are tables you want to
search, of
course you could make a join, but that depends on how things are related to
eachother.

Assume you have a array with the names of all the talbes you need to

search,
we call it $tables. Another arrya where you save the results, $found.

for(i=0;i<count($tables);i++) {
$query="SELECT * FROM " . $table[i] . " WHERE name LIKE '%x%'";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)) {
array_push($found,$row);
}
}

Now you have all the result rows stored in $found, of course you can
send/process the $row in the while loop.
Follow up has been set to proper newsgroup, alt.php.sql


Cripes! My ISP doesn't have alt.php.sql. That'd be a perfect group for a

lot of my questions! =/

So $found wouldn't have to exist before we query, right?
I do currently have another table that has all the table names in it.
eg: (but not exactly like this,)
40 tables with the following columns: id, tbl_id, name, note
Then a table (tbl_listing) with these columns: tbl_id, tbl_name
Make sense? Each row in all 40 tables has a tbl_id number that corresponds
to the table it's in, and the table tbl_listing has in each row the that
table number and its name.

So...that doesn't matter, does it? What would $table contain? The names of
all 40 tables comma separated?

Thanks for replying!
Liam

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Beyonder | last post by:
I have five tables in my database, there are actually NO common fields between them, not even a KEY or ID or anything like that, except for the "body" of a blob field. and that text is not...
1
by: TH | last post by:
I am (still :) working on a recipe database. Now I am trying to figure out how to set it up for an ingredient search. What I want it to be able to do is three things: 1. Search based on just...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
0
by: Rogelio Moreno | last post by:
Denis, I recommend you to bind the textbox controls to columns of your table inside your dataset, then get the bindingmanagerbase for the table, then use the position property of the...
4
by: Tarun Mistry | last post by:
Hi all, I have posted this in both the c# and asp.net groups as it applies to both (apologies if it breaks some group rules). I am making a web app in asp.net using c#. This is the first fully OO...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: SamKhazary | last post by:
I have created a database that has a main table with a description of different products. I have 5 other data bases that are linked sheets that have returns for the 5 different prduct groups. I'd...
3
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...
1
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
1
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...
0
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.