Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试将多个查询合并到一个查询中_Php_Mysql - Fatal编程技术网

Php 尝试将多个查询合并到一个查询中

Php 尝试将多个查询合并到一个查询中,php,mysql,Php,Mysql,*注意,如果你能想出一个更有建设性的标题,请编辑 我有一张这样的桌子: id | forGame | otherType | otherName | otherDesc 9 |+Stellar+Dawn |Character |Car |Car 10 |+Stellar+Dawn |Item |Brugson Burson |a guy 11 |+Stella

*注意,如果你能想出一个更有建设性的标题,请编辑


我有一张这样的桌子:

   id   |   forGame    |   otherType    |   otherName    |   otherDesc
9       |+Stellar+Dawn |Character       |Car             |Car
10      |+Stellar+Dawn |Item            |Brugson Burson  |a guy
11      |+Stellar+Dawn |Item            |Space Pie       |A pie from space
现在,我的问题是我试图将多个查询分离为一个查询:

$gameOther_typeItem = $database->queryDB("SELECT * FROM `mainSite_others` WHERE otherType='Item' AND forGame='$gameName'");
$gameOther_typeEntity = $database->queryDB("SELECT * FROM `mainSite_others` WHERE otherType='Entity' AND forGame='$gameName'");
$gameOther_typeCharacter = $database->queryDB("SELECT * FROM `mainSite_others` WHERE otherType='Character' AND forGame='$gameName'");
(不用担心$database->…部分,那是我的课。)


我怎样才能把这些合并成一个呢

多谢各位

选择*FROM
mainSite\u others
WHERE(otherType='Item'或otherType= 'Entity'或otherType='Character')和forGame='$gameName'

你可以用“`或'”

或者,您可以使用多个查询同时执行多个查询



我相信你要找的词是“
或”
”。你把所有的东西都倒过来了,几合一。不是一对多
SELECT * FROM my_table WHERE column1 = value1 AND column3 = value3 OR column2 = value2 AND column3 = value3
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query  = "SELECT CURRENT_USER();";
$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";

/* execute multi query */
if ($mysqli->multi_query($query)) {
    do {
        /* store first result set */
        if ($result = $mysqli->store_result()) {
            while ($row = $result->fetch_row()) {
                printf("%s\n", $row[0]);
            }
            $result->free();
        }
        /* print divider */
        if ($mysqli->more_results()) {
            printf("-----------------\n");
        }
    } while ($mysqli->next_result());
}

/* close connection */
$mysqli->close();
?>