gpt4 book ai didi

php - 在MYSQL SELECT中连接PHP变量

转载 作者:行者123 更新时间:2023-12-01 00:04:32 26 4
gpt4 key购买 nike

我正在尝试在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>";
}

}

最佳答案

$tableQuery = "SELECT * FROM table.$tableNo";


要么

$tableQuery = 'SELECT * FROM table.' . $tableNo;


要么

$tableQuery = "SELECT * FROM table.{$tableNo}";


要么

$tableQuery = sprintf("SELECT * FROM table.%s", $tableNo);

关于php - 在MYSQL SELECT中连接PHP变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21680364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com