我试图在MYSQL SELECT QUERY中连接一个PHP变量。但到目前为止没有任何效果。
$nkFetch = function($tableNo) use ($link){
$tableQuery = 'SELECT * FROM table.$tableNo'; <------------this
$res = mysqli_query($link, $tableQuery);
if (!mysqli_query($link, $tableQuery)) {
printf("Errormessage: %s\n", mysqli_error($link));
}
$table = array();
while ($row = mysqli_fetch_array($res)){
$table[] = $row;
}
shuffle($table);
foreach( $table as $row ){
echo "<li>" . $row['WORD'] . "</li>";
}
}
答案 0 :(得分:8)
$tableQuery = "SELECT * FROM table.$tableNo";
或
$tableQuery = 'SELECT * FROM table.' . $tableNo;
或
$tableQuery = "SELECT * FROM table.{$tableNo}";
或
$tableQuery = sprintf("SELECT * FROM table.%s", $tableNo);