| Welcome to Webforumz.com. |
|
Jan 26th, 2008, 15:30
|
#1 (permalink)
|
|
New Member
Join Date: Apr 2007
Location: Israel
Age: 16
Posts: 3
|
Seraching inside all tables
Hi,
I need to find the names of all the tables that have a value in a field.
For example, There are 5 tables: t1, t2, t3, t4, t5
and each one has 6 fieldsm, one of them is f4.
I need the name of all the tables that has "Felix" as a value in the f4 field.
How do I do that?
I basicly need something that will work like this incorrect piece of code:
SELECT * FROM users.* /* users is the database, * meand all tables */ WHERE `name`="Felix"
PHP MySQL.
Thank you.
Last edited by Felixr; Jan 26th, 2008 at 15:33.
|
|
|
Jan 26th, 2008, 15:35
|
#2 (permalink)
|
|
Section Manager - WOTM Assistant Editor - LZ
Join Date: May 2007
Location: Cornwall, England
Posts: 1,101
|
Re: Seraching inside all tables
Would:
- Code: Select all
SELECT * FROM users WHERE name='Felix'
Not work? Have you tried that? I'm only just starting out with MySQL so I cannot be sure.
|
|
|
Jan 26th, 2008, 23:08
|
#3 (permalink)
|
|
Administrator
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
|
Re: Seraching inside all tables
No Jack, that would only search one table.
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.
|
|
|
Jan 27th, 2008, 09:11
|
#4 (permalink)
|
|
Section Manager - WOTM Assistant Editor - LZ
Join Date: May 2007
Location: Cornwall, England
Posts: 1,101
|
Re: Seraching inside all tables
- Code: Select all
(Connect to your db) and then:
SELECT * FROM table1, table2, table3, etc (add your tables here) WHERE name='Felix'
So in PHP:
- PHP: Select all
$sql = "SELECT * FROM table1, table2, etc WHERE name='Felix'"; if ($sql) { echo 'all done'; } else { echo 'error'; }
Try that?
Remembering first you need to connect to the database:
- PHP: Select all
# DataBase Settings $hostname_config = "localhost"; # 99% Leave Localhost $database_config = ""; # Database Name $username_config = ""; # Database Username $password_config = ""; # Password $conn = mysql_connect($hostname_config, $username_config, $password_config) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($database_config)or die(mysql_error());
Last edited by Jack Franklin; Jan 27th, 2008 at 09:13.
|
|
|
Jan 27th, 2008, 12:55
|
#5 (permalink)
|
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 980
|
Re: Seraching inside all tables
I think he's asking for a way to get the table name containing the value rather than get the results themselves.
The query might look something like this
- Code: Select all
SELECT t1.f4 AS table1, t2.f4 AS table2, t3.f4 AS table3, t4.f4 AS table4, t5.f4 AS table5
FROM t1
LEFT JOIN t2 ON (t1.f4=t2.f4)
LEFT JOIN t3 ON (t2.f4-t3.f4)
LEFT JOIN t4 ON (t3.f4=t4.f4)
LEFT JOIN t5 ON (t4.f4=t5.f4)
WHERE t1.f4 = 'felix' OR t2.f4 = 'felix' OR t3.f4 = 'felix OR t4.f4 = 'felix' OR t5.f4 = 'felix'
That query above will give alarge result set but basically the columns it returns will be named table1-5 respectively. It's then a matter of checking if any of the rows return have a value of felix under table-15
|
|
|
Jan 27th, 2008, 13:08
|
#6 (permalink)
|
|
New Member
Join Date: Apr 2007
Location: Israel
Age: 16
Posts: 3
|
Re: Seraching inside all tables
Thanks, but I meant that there are way to many tables for my to just enter their names...
I need to search inside all of them.
|
|
|
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|