查询失败:您的SQL语法有错误;查看与MySQL对应的手册



我被迫更新到MySQL 5和PHP 5,因为我的服务提供商不再支持旧版本。我有一个使用MySQL搜索的工作网站,它运行得很好。以下是放置在用户列表页面上的include。当我取出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>

您可能需要用引号将$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()); 

相关内容

  • 没有找到相关文章

最新更新