我的选择:
$query = "SELECT * FROM user where userID='1';";
在我的 mysqli_multi_query() 中没有返回整行,它只返回一列。
这是我的结果:
1-----------------book1 book3 book4
但这就是我想要的:
1 John Jan-26 4-----------------book1 book3 book4
这是我的两张表:
Table1: user
| userID | name | date | booksRead
---------------------------------------------------------------------
| 1 | John | Jan-26 | 4
| 2 | Andy | Jan-27 | 7
| 3 | Mark | Jan-28 | 8
Table 2: booksCheckedOut
row | userID | book | date
-------------------------------------------------
1 | 1 | book1 | Jan-26
2 | 2 | book2 | Jan-27
3 | 1 | book3 | Jan-28
4 | 1 | book4 | Jan-29
这是我的php代码:
<?php
$mysqli = new mysqli("localhost","root","password","database_name");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT * FROM user where userID='1';";
$query .= "SELECT book FROM booksCheckedOut where userID='1';";
if ($mysqli->multi_query($query)) { // execute multi query
do {
if ($result = $mysqli->store_result()) { // store first result
while ($row = $result->fetch_row()) {
printf("%s\n", $row[0]);
}
//$result->close();
}
if ($mysqli->more_results()) { /* print divider */
printf("-----------------\n");
}
} while ($mysqli->next_result());
}
$mysqli->close();
?>
有谁知道我做错了什么?
提前致谢!