我希望得到一些帮助:我正在尝试输出一个用户可以通过各种选择字段查看和排列的 mysql 数据表。我希望数据按日期顺序自动排列(最新的在前),并且每页限制为 10 个结果。
我有以下脚本摘录(为简洁起见,我已将其截断,如有必要,我很乐意发布更多内容)...
<!-- **** THIS CODE CREATES THE FORM ****-->
<form id="form1" name="form1" method="post" action="deals.php">
<!-- **** THIS CODE IS FOR THE "FROM" DATE ****-->
<label for="from">From</label>
<input name="from" type="text" id="from" size="10" value="<?php echo $_REQUEST["from"]; ?>" />
Results will only show offers that have been listed since this date. Leave blank for all offers.
<!-- **** THIS CODE IS FOR THE "TO" DATE ****-->
</p>
<label for="to">To</label>
<input name="to" type="text" id="to" size="10" value="<?php echo $_REQUEST["to"]; ?>"/>
Results will only show offers that run until this date. Leave blank for all offers.
<label>Country</label>
<select name="country">
<option value="">--Any--</option>
<?php
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY country ORDER BY country";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
while ($row = mysql_fetch_assoc($sql_result)) {
echo "<option value='".$row["country"]."'".($row["country"]==$_REQUEST["country"] ? " selected" : "").">".$row["country"]."</option>";
}
?>
</select>
Only shows offers from the selected country.
// ***************************************** // ***** ** 重复每个变量(我真的应该将它设置为一个数组 ******************************* // *****************************************
if ($_REQUEST["from"]<>'' and $_REQUEST["to"]<>'')
{
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE from_date >= ' ORDER BY from_date DESC LIMIT 0, 10 ".mysql_real_escape_string($_REQUEST["from"])."' AND to_date <= '".mysql_real_escape_string($_REQUEST["to"])."'".$search_Seller.$search_country.$search_id.$search_Offer.$search_Item.$search_Description.$search_Brand.$search_Was.$search_Now;
}
else if ($_REQUEST["from"]<>'')
{$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE from_date >= ' ORDER BY from_date DESC LIMIT 0, 10".mysql_real_escape_string($_REQUEST["from"])."'".$search_Seller.$search_country.$search_id.$search_Offer.$search_Item.$search_Description.$search_Brand;
}
else if ($_REQUEST["to"]<>'')
{$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE to_date <= ' ORDER BY date_time DESC LIMIT 0, 10".mysql_real_escape_string($_REQUEST["to"])."'".$search_Seller.$search_country.$search_id.$search_Offer.$search_Item.$search_Description.$search_Brand.$search_Was.$search_Now;}
else {$sql = "SELECT * FROM ".$SETTINGS["data_table"]." ORDER BY from_date DESC LIMIT 0, 10 ".$search_Seller.$search_country.$search_id.$search_Offer.$search_Item.$search_Description.$search_Brand.$search_Was.$search_Now;
}
这在输出初始表时非常有效,但是,一旦用户输入任何数据,我就会收到错误
"request "Could not execute SQL query" SELECT * FROM newoffers ORDER BY from_date DESC LIMIT 0, 10 AND country='UK'"
所以我猜语法有问题?我试过重新安排最后一部分,所以它写着:
else {$sql = "SELECT * FROM ".$SETTINGS["data_table"]. .$search_Seller.$search_country.$search_id.$search_Offer.$search_Item.$search_Description.$search_Brand.$search_Was.$search_Now; "ORDER BY from_date DESC LIMIT 0, 10";
}
结果:解析错误:语法错误,意外'"ORDER BY from_date DESC LIMIT' (T_CONSTANT_ENCAPSED_STRING) in /home/iratebjj/public_html/dealstest.php on line 267
请查看http://www.iratebjj.com/dealstest.php以查看正在运行的脚本。如果有人有任何建议,我真的很感激!
谢谢!
希望这个帖子没问题。我想我已经遵循了所有的准则!