dougou6727 2012-08-31 09:59
浏览 31

SQL语法错误urgnet [关闭]

I have this scrip that reports

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-5,5' at line 1

And can't seem to find the error.

This is the script would be happy to get any help.

<?
require_once("conn.php");
require_once("includes.php");
require_once("templates/HeaderTemplate.php");
require_once("pageList.php");
//  ADVANCED SEARCH
//require_once("advanced.php");
//require_once("templates/AdvancedSearchTemplate.php");
$showall = false;
if ($_REQUEST['stateid']) {
    $sql = "Select full_name From states where state_id = ".$_REQUEST['stateid'];
    $myr = mysql_query($sql) or die(mysql_error());
    $isAny = mysql_num_rows($myr);
    $state_name = mysql_fetch_array($myr);
    $show = "<table width=\"550\"><tr><td>Showing Listings For <font color=\"FF0000\" >$state_name[full_name]</font></td></tr></table>"; 
}       
else {
    $show = "Showing All Listings"; 
    $showall = true;
}

//print "The Value Of ... ".$isAny;
//echo "<BR><b>&nbsp;&nbsp;&nbsp;".$show;
if ($_REQUEST['stateid'])
    $addsql = "and re_listings.state_id=".$_REQUEST['stateid'];
else
    $addsql ="";
$q1 = "select * from re_listings, re_agents, re_priority where re_listings.AgentID = re_agents.AgentID and re_agents.PriorityLevel = re_priority.PriorityLevel and re_agents.AccountStatus = 'active' ".$addsql;
$rsQ = mysql_query($q1);
$total_records = mysql_num_rows($rsQ);
if($total_records== 0)
{
        $ListingTable = "<table align=center width=500 cellspacing=0>
";
    $ListingTable .= "<tr>
<td>$links</td></tr>
\t";
    $ListingTable .= "<tr>
<td>&nbsp;</td></tr>
\t";
    $ListingTable .= "</tr>
</table>

";
    $ListingTable .= "<br><br><center><Strong>No Results Was Found!</Strong></center>";
require_once("templates/HeaderTemplate.php");
require_once("templates/SearchTemplate.php");   
require_once("templates/FooterTemplate.php");
}
$records_per_page = 5; // no of records per page
$current_page_no = 1;

    if ($_REQUEST['page'])
    {
        $current_page_no = $_REQUEST['page'];
    } 
    $pageL = new pageList($total_records, $records_per_page, $current_page_no);
    $pageL->generate();
//print $addsql."<BR>";
//print "startRecord: ".$pageL->startRecord;
$q2 = "select * from re_listings, re_agents, re_priority where re_listings.AgentID = re_agents.AgentID and re_agents.PriorityLevel = re_priority.PriorityLevel and re_agents.AccountStatus = 'active' ".$addsql." order by visits desc LIMIT $pageL->startRecord,$pageL->numOfRows";
$r1 = mysql_query($q2) or die(mysql_error());
$lrows = mysql_num_rows($r1);
if($lrows > '0')
{
    $ListingTable .= "<table align=center width=500 cellspacing=0>
";

    $ListingTable .= "<tr>
<td width=75>&nbsp;</td>
\t";

//  $ListingTable .= "<td width=200 align=center><a class=BlackLink href=\"search.php?c=$_GET[c]&s=$_GET[s]&AgentID=$_GET[AgentID]&search_city=$_GET[search_city]&search_state=$_GET[search_state]&search_country=$_GET[search_country]&search_PropertyType=$_GET[search_PropertyType]&MinPrice=$_GET[MinPrice]&MaxPrice=$_GET[MaxPrice]&rooms1=$_GET[rooms1]&rooms2=$_GET[rooms2]&bath1=$_GET[bath1]&bath2=$_GET[bath2]&before=$_GET[before]&school=$_GET[school]&transit=$_GET[transit]&park=$_GET[park]&ocean_view=$_GET[ocean_view]&lake_view=$_GET[lake_view]&mountain_view=$_GET[mountain_view]&ocean_waterfront=$_GET[ocean_waterfront]&lake_waterfront=$_GET[lake_waterfront]&river_waterfront=$_GET[river_waterfront]&city=1&page=$_REQUEST[page]\">address</a></td>
\t";

//  $ListingTable .= "<td width=125 align=center><a class=BlackLink href=\"search.php?c=$_GET[c]&s=$_GET[s]&AgentID=$_GET[AgentID]&search_city=$_GET[search_city]&search_state=$_GET[search_state]&search_country=$_GET[search_country]&search_PropertyType=$_GET[search_PropertyType]&MinPrice=$_GET[MinPrice]&MaxPrice=$_GET[MaxPrice]&rooms1=$_GET[rooms1]&rooms2=$_GET[rooms2]&bath1=$_GET[bath1]&bath2=$_GET[bath2]&before=$_GET[before]&school=$_GET[school]&transit=$_GET[transit]&park=$_GET[park]&ocean_view=$_GET[ocean_view]&lake_view=$_GET[lake_view]&mountain_view=$_GET[mountain_view]&ocean_waterfront=$_GET[ocean_waterfront]&lake_waterfront=$_GET[lake_waterfront]&river_waterfront=$_GET[river_waterfront]&r=1&page=$_REQUEST[page]\">bed, bath, garage</a></td>
\t";

//  $ListingTable .= "<td align=center width=100><a class=BlackLink href=\"search.php?c=$_GET[c]&s=$_GET[s]&AgentID=$_GET[AgentID]&search_city=$_GET[search_city]&search_state=$_GET[search_state]&search_country=$_GET[search_country]&search_PropertyType=$_GET[search_PropertyType]&MinPrice=$_GET[MinPrice]&MaxPrice=$_GET[MaxPrice]&rooms1=$_GET[rooms1]&rooms2=$_GET[rooms2]&bath1=$_GET[bath1]&bath2=$_GET[bath2]&before=$_GET[before]&school=$_GET[school]&transit=$_GET[transit]&park=$_GET[park]&ocean_view=$_GET[ocean_view]&lake_view=$_GET[lake_view]&mountain_view=$_GET[mountain_view]&ocean_waterfront=$_GET[ocean_waterfront]&lake_waterfront=$_GET[lake_waterfront]&river_waterfront=$_GET[river_waterfront]&p=1&page=$_REQUEST[page]\">price</a></td>
";

    $ListingTable .= "</tr>
</table>

";
    $ListingTable .= "<table align=center width=500 border=0 bordercolor=#336699 rules=rows cellspacing=0>
";

$start = $pageL->startRecord+1;
$end = $records_per_page*$current_page_no;
$totalpages = $pageL->getTotalPage();
if ($current_page_no==$totalpages)
$end = $pageL->getTotalRecords();
    $rec_info = "<strong>Showing Listings $start - $end</strong>";
    $ListingTable .= "<tr>
<td colspan=4>$rec_info</td></tr>
\t";

    while($a1 = mysql_fetch_array($r1))
    {

        $ListingTable .= "<tr style=\"border-width:1; border-color:blue\" onMouseOver=\"this.style.background='#FFFFFF'; this.style.cursor='hand'\" onMouseOut=\"this.style.background='white'\" onClick=\"window.open('info.php?id=$a1[ListingID]', '_top')\">
\t";

        $ListingTable .= "<td height=60>";
        $ListingTable .= "<table align=center width=\"100%\">
";

        $ListingTable .= "<TR style=\"background-color:#001592; color:white; font-family:verdana; font-size:11; font-weight:bold; height=20px \">
<TD colspan=4>
$a1[PriorityName] listing</TD>
</TR>
";
//      $ListingTable .= "<caption align=left><span class=RedLink>$a1[PriorityName] listing</span></caption>
";
        $ListingTable .= "<tr>
\t<td width=75>";
//Price formatting
        $MyPrice = number_format($a1[Price], 2, ".", "'");
//State Formatting
    if(empty($a1[state_id]))
        $state = "Not Available";
    else
        {
            $state_id = $a1[state_id];
            $sql = "Select full_name from states where state_id=$state_id";
            $myrs = mysql_query($sql) or die(mysql_error());
            $statename = mysql_fetch_array($myrs);
            $state = $statename[full_name];

        }

    $ListingTable =$ListingTable."<TR bgcolor=\"D2EEFF\"><TD width=\"20%\"><b>Country: </b></TD><TD width=\"20%\"> $a1[country]</TD>";
    $ListingTable =$ListingTable."<TD width=\"20%\"><b>State: </b></TD><TD width=\"20%\">$state</TD></TR>";
    $ListingTable =$ListingTable."<TR bgcolor=\"FFFFFF\">
\t<td valign=top width=\"20%\"><B>City: </b></td><td valign=top width=\"20%\">$a1[city]</td>";
    $ListingTable =$ListingTable."<TD width=\"20%\"><b>Address: </b></TD><TD width=\"20%\"> $a1[address]</TD></TR>";
    $ListingTable =$ListingTable."<TR bgcolor=\"D2EEFF\"><TD width=\"20%\"><b>Price: </b></TD><TD width=\"20%\"> $$MyPrice</TD>";
    $ListingTable =$ListingTable."<TD width=\"20%\"><b>SqMeters: </b></TD><TD width=\"20%\"> $a1[SquareMeters] sq.m.</TD</TR>";
        $ListingTable .= "</td>
\t";
        $ListingTable .= "</tr>
";

        $ListingTable .= "<HR>";
        $ListingTable .= "</table>

</td>
</tr>

";
    }
    $ListingTable .= "</table>";

}
else
{
    $ListingTable = "<table align=center width=500 cellspacing=0>
";
//  $ListingTable .= "<tr>
<td>$links</td></tr>
\t";
    $ListingTable .= "<tr>
<td>&nbsp;</td></tr>
\t";
    $ListingTable .= "</tr>
</table>

";
    $show = "<table align=center width=550 cellspacing=0><tr><td><br><br><center><Strong>No Results Was Found!</Strong></center></td></tr></table>";

}   
echo "<BR><b>&nbsp;&nbsp;&nbsp;".$show;
/*
 if ($_REQUEST['stateid'] == 0){ 
echo "<table border=0 align=center><tr><td align=center><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"400\" height=\"275\">
  <param name=\"movie\" value=\"usmap.swf\">
  <param name=\"quality\" value=\"high\">
  <embed src=\"usmap.swf\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"500\" height=\"325\"></embed>\"
</object></td></tr></table>";
 }*/

require_once("templates/SearchTemplate.php");
require_once("templates/FooterTemplate.php");
?>
  • 写回答

3条回答 默认 最新

  • douyin7829 2012-08-31 10:04
    关注

    Although it isn't apparent in the code, I think the query that is casuing error is this one:

    $q2 = "
    
    select 
        * 
    from 
        re_listings, 
        re_agents, 
        re_priority 
    where 
        re_listings.AgentID = re_agents.AgentID 
        and re_agents.PriorityLevel = re_priority.PriorityLevel 
        and re_agents.AccountStatus = 'active' 
        ".$addsql." 
    order by 
        visits desc 
    LIMIT 
        $pageL->startRecord,$pageL->numOfRows
    ";
    

    You are probably passing a negative value in the limit clause, which you can't do.

    You should check if $pageL->startRecord is less than 0 and if it is, change it to zero.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?