0

我在使用下面的代码时遇到了问题,它给了我一个语法错误,我在手册或网上找不到任何关于它的内容。你对我如何让它运行有什么想法?

第一次尝试:

<?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 ('Buyer','Seller','Buyer/Seller','Investor') AND status = 'New' ORDER BY da' 行附近使用1

4

3 回答 3

0

你有一段;时间后的情况。

while ($row = mysqli_fetch_array($result)); {

应该

while ($row = mysqli_fetch_array($result)) {
于 2012-07-01T03:59:08.713 回答
0

删除 =。

contacttype IN

不是

contacttype = IN
于 2012-07-01T04:08:57.370 回答
0

试试这个查询

$sql = "SELECT * FROM contacts WHERE contacttype IN('".$typeslist."') AND status = 'New' ORDER BY date DESC";
于 2012-07-01T08:36:11.450 回答