How to selct select in 2 table

Discussion in 'PHP' started by hexmax, Feb 8, 2009.

  1. #1
    Hello all

    i have small issue in script i need to select insert data from 2 table but i got error

    this is my Current code

    <?php 
    $q= mysql_query("select * from `$table_01` order by `ts_03` asc",$l);
    while($r= mysql_fetch_array($q)){  
    extract($r);
    ?>			
    <option value="<?php echo $ts_id ;?>"><?php echo $ts_01 ;?></option>
    <?php }?>
    Code (markup):
    you can see it's query from $table_01 only how i can add $table_02 in that code ?
     
    hexmax, Feb 8, 2009 IP
  2. steelaz

    steelaz Peon

    Messages:
    47
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The syntax to select from two tables at the same time is:

    SELECT * FROM `table1`, `table2` WHERE ...
    Code (markup):
    What exactly are you trying to achieve?
     
    steelaz, Feb 8, 2009 IP
  3. vipinc007

    vipinc007 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    to select data from two tables at a time u have to join the 2 tables or use union queries.
     
    vipinc007, Feb 9, 2009 IP
  4. kellywriter

    kellywriter Banned

    Messages:
    81
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can select it using select a.table1, b.table2 from table1,table2 like this from two tables.
     
    kellywriter, Feb 9, 2009 IP