我遇到下面的代码有问题,它给了我一个语法错误,我在手册或网上找不到任何关于它的内容。关于如何让它运行起来你有什么想法?
第一次尝试:
<?php
require("../dbpass.php"); $types = array('Buyer','Seller','Buyer / Seller','Investor');
$typeslist = implode ("','", $types);
$sql = "SELECT * FROM contacts WHERE contacttype IN ('$typeslist') AND status = 'New' ORDER BY date DESC";
$result = mysqli_query($mysqli,$sql) or die ("Error: ".mysqli_error($mysqli));
while ($row = mysqli_fetch_array($result)) {
第二次尝试(在“IN”之后加上“=”):
<?php
require("../dbpass.php");
$types = array('Buyer','Seller','Buyer / Seller','Investor');
$typeslist = implode ("','", $types);
$sql = "SELECT * FROM contacts WHERE contacttype = IN ('$typeslist') AND status = 'New' ORDER BY date DESC";
$result = mysqli_query($mysqli,$sql) or die ("Error: ".mysqli_error($mysqli));
while ($row = mysqli_fetch_array($result)) {
这是代码的其余部分:
$firstname = $row ['firstname'];
echo'.$firstname.';
}
?>
错误:您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在'IN('买方','卖方','买方/卖方','投资方')附近使用正确的语法,并且状态='新'ORDER BY da'在线1
答案 0 :(得分:0)
在你的状态之后你有一个;
。
while ($row = mysqli_fetch_array($result)); {
应该是
while ($row = mysqli_fetch_array($result)) {
答案 1 :(得分:0)
删除=。
contacttype IN
不
contacttype = IN
答案 2 :(得分:0)
尝试此查询
$sql = "SELECT * FROM contacts WHERE contacttype IN('".$typeslist."') AND status = 'New' ORDER BY date DESC";