我被迫更新到MySQL 5和PHP 5,因为我的服务提供商不再支持旧版本。我有一个工作网站,这个MySQL搜索工作正常。以下是放置在用户列表页面上的内容。当我取出SQL语句并在服务器上运行它时,它返回正确的结果。我的猜测是它与格式化有关。任何想法,为什么我可能会收到此错误?
“查询失败:您的SQL语法出错;请查看与您的MySQL服务器版本对应的手册,以便在第1行'ORDER BY x.id_have LIMIT 0,30'附近使用正确的语法”
使用此语法
<table cellpadding="15" border="0">
<tr>
<td valign="top">
So far, the following members have these items which match;
<ul>
<?
$peoplewhomatch = mysql_query("SELECT x.id_customer, g.title Have, c.user_name as Member, g.title gwants, gg.title Has, y.id_customer x_username
FROM Want x
JOIN Want y
ON (y.id_sellversion,y.id_version) = (x.id_version,x.id_sellversion)
inner join Version as v
on x.id_version = v.id_version
inner join Version as vv
on y.id_version = vv.id_version
inner join Game as g
on g.id_game = vv.id_game
inner join Customer as c
on y.id_customer = c.id_customer
inner join Game as gg
on gg.id_game = v.id_game
WHERE x.id_have = $hid
ORDER BY x.id_have
LIMIT 0, 30")or die("Query failed: " . mysql_error());
while($row = mysql_fetch_array($peoplewhomatch))
{ ?>
<span class='greenitalic'><?=$row['Member']?></span> has <span class='highshadow'><?=$row['Has']?></span> and wants <span class='ishadow'><?=$row['gwants']?></span><BR><?}?>
</td>
</tr>
</table>
答案 0 :(得分:0)
您可能需要将$hid
括在引号中,如下所示:
$peoplewhomatch = mysql_query("SELECT x.id_customer, g.title Have, c.user_name as Member, g.title gwants, gg.title Has, y.id_customer x_username
FROM Want x
JOIN Want y
ON (y.id_sellversion,y.id_version) = (x.id_version,x.id_sellversion)
inner join Version as v
on x.id_version = v.id_version
inner join Version as vv
on y.id_version = vv.id_version
inner join Game as g
on g.id_game = vv.id_game
inner join Customer as c
on y.id_customer = c.id_customer
inner join Game as gg
on gg.id_game = v.id_game
WHERE x.id_have = '$hid'
ORDER BY x.id_have
LIMIT 0, 30")or die("Query failed: " . mysql_error());