Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Same query to get data from different tables
Old 03-06-2010, 03:08 PM Same query to get data from different tables
Super Talker

Posts: 128
Name: Jose daSilva
Trades: 0
Hi
I have in the same database different tables:
Inter_main_USA
Inter_main_Canada
Inter_main_Uk
And so on...

How can I in the same query in order to list me all the countries if meet the conditions sales=’1’ and active=’1’.
I did:
$country=$_GET['country'];

$database="name";
$connect = mysql_connect ("server", "username", "pass") or die ("bla...bla...");
mysql_select_db($database, $connect) or die ("bla...bla...");

$sql="select * from inter_main_".country." where sales = '1' and active = '1' group by country asc";
$result = mysql_db_query("database", $sql);
<? while($regist=mysql_fetch_array($result)){
$arr=$regist ['country']; ?>

<tr>
<td><? echo substr($arr, 0,24); ?>.</a></b></td>
</tr>
<? } ?>

This only gives me the list of countries in the country column that are in the same table: inter_main
Thanks
josil is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-06-2010, 03:19 PM Re: Same query to get data from different tables
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Use a UNION query

SELECT fieldlist FROM table WHERE criteria
UNION
SELECT fieldlist FROM table1 WHERE criteria
UNION
SELECT fieldlist FROM table2 WHERE criteria
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Same query to get data from different tables
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.39487 seconds with 12 queries