Mysql& PHP:在不同的mysql表中搜索

时间:2012-09-18 13:33:47

标签: php mysql

我从用户那里获得一个输入,检查db中的值,如果正确则执行某些操作,如

    $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 

           }

我可以使用union运算符吗?

现在我想要如果上面的查询失败,那么在另一个表中搜索$getuser_key

我只是想知道这是否可能,如果是这样的话呢?

1 个答案:

答案 0 :(得分:2)

JOIN他们:

 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'