PHP MySQL WHERE子句列名错误

时间:2015-10-30 07:58:52

标签: php mysql

MySQL查询:

$sSix = "SELECT count(*) as count FROM `timers` WHERE `real_id` = {$row['real_id']}";
$rSix = mysql_query($sSix, $conn2);
echo mysql_error(); die;

结果: 未知栏' 985_1445542200'在' where子句'

列名称为real_id,但结果显示列' 985_1445542200'。

请您告诉我可能的错误原因。

2 个答案:

答案 0 :(得分:5)

WHERE部分需要引号。像这样:

$sSix = "SELECT count(*) as count FROM `timers` WHERE `real_id` = '{$row['real_id']}'";

此外,请考虑使用较新的mysqli_函数或PDO,因为旧的mysql_函数将来会停止工作。

答案 1 :(得分:0)

$respons = array();
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
  $respons[$i]["error"] = FALSE;
  $respons[$i]["WinnerInfo"]["price"] = $row["price"];
  $respons[$i]["WinnerInfo"]["level"] = $row["level"];
  $respons[$i]["WinnerInfo"]["win_date"] = $row["win_date"];
  $respons[$i]["WinnerInfo"]["payed"] = $row["payed"];
  $respons[$i]["WinnerInfo"]["pay_date"] = $row["pay_date"];
  ++$i;
}