www.webdeveloper.com
Results 1 to 3 of 3

Thread: Same query to get data from more that one tables

  1. #1
    Join Date
    Jul 2006
    Posts
    152

    Same query to get data from more that one tables

    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
    Last edited by JoseSilva; 03-06-2010 at 02:31 PM. Reason: RESOLVED

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    The right question to ask is, "how do I normalize my database tables", and the answer is here. If you are forced to stick with your current structure you could UNION results from all three tables but you aren't really gaining anything much there. The cause of the issue is your database structure so I would suggest fixing that rather than trying to work around it.
    The first rule of Tautology Club is the first rule of Tautology Club.

  3. #3
    Join Date
    Jul 2006
    Posts
    152
    Resolved

    Thanks a Lot

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles