1

i am getting a input from user checking that value in db and if correct then doing some operation like

    $getuser_key = $_POST['keyy'];

    $sql = "SELECT *  from demo_participant WHERE meeting_id_id IN(SELECT id FROM demo_meeting WHERE meetingID = '$get_meetingid') and `key` = '$get_meetinkey'";
    mysql_real_escape_string($sql);
    $result = mysql_query($sql) or die (mysql_error());
    while ($row = mysql_fetch_array($result)) {

          somthing 

           }

Can i use union operator ?

Now i want if the above query get failed then search $getuser_key in another table

I just want to know that it is possible in this way or not if it is then how ?

JSK NS
  • 3,346
  • 2
  • 25
  • 42
user1667633
  • 4,449
  • 2
  • 16
  • 21
  • 3
    Welcome to Stack Overflow! Please, don't use `mysql_*` functions to write new code. They are no longer maintained and the community has begun [deprecation process](http://goo.gl/KJveJ). See the *[red box](http://goo.gl/GPmFd)*? Instead you should learn about [prepared statements](http://goo.gl/vn8zQ) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you can't decide which, [this article](http://goo.gl/3gqF9) will help you. If you pick PDO, [here is good tutorial](http://goo.gl/vFWnC). – Madara's Ghost Sep 18 '12 at 13:35
  • use joins for multiple tables – M Khalid Junaid Sep 18 '12 at 13:36
  • Why, I just wrote a really lengthy question and answer that covers this exact [sort of question](http://stackoverflow.com/questions/12475850/how-can-an-sql-query-return-data-from-multiple-tables) which I hope will help to clarify how joins work on tables and how to get information from multiple tables in your database! – Fluffeh Sep 18 '12 at 13:36
  • @wes db is created by django orm and i am using in php got it – user1667633 Sep 18 '12 at 13:43

1 Answers1

2

JOIN them:

 SELECT *  
 from demo_participant dp
 INNER JOIN demo_meeting dm ON dp.meetingID = dm.meetingID 
        AND dm.Key = '$get_meetinkey'
 INNER JOIN demo_thirdTable dt ON -- Somecondition here
 WHERE dp.key = '$get_meetinkey'
Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164