<?php
include "head-main.php";
include "conn.php";
if(isset($_GET)){ $var = $_GET["cat"]; }
$data = mysql_query('SELECT kampword FROM data_dict where category=$var');
$retval = mysql_query( $data, $conn );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_assoc($retval)) {
echo "World :{$row['kampword']} <br> ".
"--------------------------------<br>";
}
?>
我是编程新手,我无法追查我的代码有什么问题,你能帮助我吗?我正在尝试在我的数据库上打印一些数据
我总是得到这个错误 “无法获取数据:查询为空”
答案 0 :(得分:0)
您正在两次调用mysql_query
函数。尝试用以下代码替换你的行:
<?php
if(isset($_GET["cat"])) {
$var = $_GET["cat"];
$retval = mysql_query('SELECT kampword FROM data_dict where category=$var');
}else {
$retval = false;
}
答案 1 :(得分:0)
$data = mysql_query("SELECT kampword FROM data_dict where category=$var");
或
$data = mysql_query('SELECT kampword FROM data_dict where category="'.$var.'"');
答案 2 :(得分:0)
尝试
if(isset($_GET["cat"])){ $var = $_GET["cat"]; }