如何从MySQL数组中设置多个值获取并检查数组键

时间:2016-06-14 10:38:08

标签: php mysql arrays

我试图从MySQL数组获取值多值获取并检查数组键是否存在。

我有两个不同的表格booking_infoticket_details如果两个ID相同,则从ticket_details获取值

function getSeatInfo()
{
    global $getseatinfo;
    $id = 1;
    $sql = "SELECT id FROM booking_info WHERE id = '". $id . "'"; 
    $sqlr = "SELECT * FROM ticket_details WHERE id = '". $$sql . "'"; 
    $res = mysql_query($sqlr);

    $c=0;
    while ($a_row = mysql_fetch_array($res)) {
        $getseatinfo[$c]["id"] = $a_row["id"];
        $getseatinfo[$c]["seat_number"] = $a_row["seat_number"];

        $c++;
    }
    return $getseatinfo;
}

并检查值是否存在

global $getseatinfo;
$values=array('A1','A2','A3','B1','B2','B3');

if (array_key_exists($values,$getseatinfo)) {
    echo "Key exists!";
} else {
    echo "Key does not exist!";
}

1 个答案:

答案 0 :(得分:0)

执行以下查询:

        $id = 1;
        $sql = "SELECT bi.id,td.* FROM booking_info bi WHERE bi id = '". $id."' "; 
        $sql .= "LEFT JOIN ticket_details td ON td.id = bi.id";