ช่วยทีครับ การค้นหาแบบแบ่งหน้าครับ หน้าแรกแสดงผลปกติ แต่พอไปที่หน้า 2 กลับไม่แสดงครับ
error ครับ >>>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 'order by id desc limit 10,10' at line 1
select * from product where status='y' and num!='0' and(ckMoney= order by id desc limit 10,10;
Date :
2011-08-16 23:32:59
By :
nuntza
ผิดตรงนี้ครับ แต่ผมดูจากโค๊ดมัีนไม่น่าจะเป็นแบบนี้ มีอะไรมากกว่านี้หรือเปล่าครับ
select * from product where status='y' and num!='0' and(ckMoney= order by id desc limit 10,10;
Date :
2011-08-17 00:08:55
By :
ikikkok
Code (PHP)
<?
session_start();
include("config_db.php");
if ($ssid_brand!="") {
$qsearch1="and (id_brand='$ssid_brand') ";
}
if ($ssid_generation!="") {
$qsearch2="and (id_generation='$ssid_generation') ";
}
if ($ssid_color!="") {
$qsearch5="and (id_color='$ssid_color') ";
}
if ($ssprice_a!="") {
$qsearch3="and (price>='$ssprice_a') ";
}
if ($ssprice_b!="") {
$qsearch4="and (price<='$ssprice_b') ";
}
if (($mmonth!="") and ($myear!="")) {
$ckmy="$mmonth-$myear";
$qsearch6="and(ckMoney='$ckmy')";
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/index.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<!-- InstanceBeginEditable name="doctitle" -->
<title><?=$web_title;?></title>
<!-- InstanceEndEditable -->
<link href="css/home_style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-image: url(images/bg.gif);
background-color: #FFB577;
}
.style111 {color: #FFFFFF}
.style1 {
color: #FF6600;
font-size: 16px;
font-weight: bold;
}
.style5 {font-size: 14px;
color: #FF0000;
}
.style6 { color: #FFFFFF;
font-weight: bold;
}
.style7 {font-size: 14px}
-->
</style>
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
.style6 {color: #FFFFFF}
.style113 {color: #9900FF}
.style114 {
color: #FF0000;
font-weight: bold;
}
-->
</style>
<!-- InstanceEndEditable -->
</head>
<body>
<div align="center">
<table width="950" border="0" cellpadding="2" cellspacing="2" bgcolor="#FEE7A3">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="950" height="180" border="0" cellpadding="0" cellspacing="0" background="images/logo.jpg">
<tr>
<td valign="top"><div align="right" class="upper_bold_green44">
<table width="100%" height="130" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="2%"> </td>
<td width="35%"> </td>
<td width="63%" height="105" valign="top"><div align="right"></div>
<div align="right"></div></td>
</tr>
<tr>
<td height="75" colspan="3" valign="bottom" class="upper_bold_green_big"><?
$login=$_SESSION['username'];
$sql_log = "select * from member where username='$login'";
$result_log = mysql_query($sql_log);
While($row_login= mysql_fetch_array($result_log)){
$id_log= $row_login['id'];
$prefix_log= $row_login['prefix'];
$fname_log= $row_login['fname'];
$lname_log= $row_login['lname'];
$type_log= $row_login['type'];
$company_log= $row_login['company'];
$sql_log2 = "select * from member_type where id='$type_log'";
$result_log2 = mysql_query($sql_log2);
While($row_login2= mysql_fetch_array($result_log2)){
$typetxt_log= $row_login2['type'];
}
?>
<span class="upper_bold_green_big"><strong>ยินดีต้อนรับ ::</strong>
<?=$prefix_log;?>
<?=$fname_log;?>
<?=$lname_log;?>
<strong>[
<?=$typetxt_log;?>
]</strong></span>
<? } ?></td>
</tr>
</table>
</div>
<div align="left"></div></td>
</tr>
</table></td>
</tr>
<tr>
<td height="25" background="images/bar3.jpg"><table width="100%" height="18" border="0" cellpadding="2" cellspacing="2" bgcolor="#280001">
<tr>
<td width="7%" height="22" bgcolor="#813B00"><div align="center"><a href="index.php" ><span class="style6" >หน้าแรก</span></a></div></td>
<?php if ($_SESSION['username'] == ""){ ?> <td width="16%" bgcolor="#813B00"><div align="center"><a href="regis_low.php" ><span class="style6">สมัครสมาชิกผู้ฝากขาย</span></a></div></td>
<? } ?>
<?php if ($_SESSION['username'] == ""){ ?><td width="14%" bgcolor="#813B00"><div align="center"><a href="regis2_low.php" ><span class="style6" >สมัครสมาชิกผู้ซื้อ</span></a></div></td><? } ?>
<?php if ($_SESSION['username'] != ""){ ?><td width="12%" bgcolor="#813B00"><div align="center"><a href="regis_detail.php" ><span class="style6" >ข้อมูลส่วนตัว</span></a></div></td><? } ?>
<td width="10%" bgcolor="#813B00"><div align="center"><a href="web_buy.php" ><span class="style6" >วิธีการสั่งซื้อ</span></a></div></td>
<td width="13%" bgcolor="#813B00"><div align="center"><a href="web_pay.php" ><span class="style6" >วิธีการชำระเงิน</span></a></div></td>
<td width="8%" bgcolor="#813B00"><div align="center"><a href="webboard.php" ><span class="style6" >เว็บบอร์ด</span></a></div></td>
<td width="8%" bgcolor="#813B00"><div align="center"><a href="web_content.php" ><span class="style6" >ติดต่อเรา</span></a></div></td>
<?php if ($_SESSION['username'] != ""){ ?><td width="12%" bgcolor="#813B00"><div align="center"><a href="logout.php" ><span class="style6" >ออกจากระบบ</span></a></div></td><? } ?></tr>
</table></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="200" valign="top" bgcolor="#B35100"><? include("menu.php"); ?></td>
<td width="1" bgcolor="#FFE7D2"> </td>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><? include("menu_head.php"); ?></td>
</tr>
<tr>
<td><!-- InstanceBeginEditable name="EditRegion1" -->
<table width="100%" border="0" cellspacing="0">
<tr>
<td height="300" valign="top"><div align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#FFFFFF">
<td width="100%" height="25" bgcolor="#BF5600"><div align="left" class="style6"><strong>:: เปรียบเทียบข้อมูลสินค้า </strong></div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>
<table width="100%" height="19" border="0" cellpadding="2" cellspacing="2" bgcolor="#FFF9F4">
<tr>
<td colspan="5" valign="top" bgcolor="#E4F3FA"><div align="center">
<form id="form1" name="form1" method="post" action="">
<table width="50%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFC595">
<tr>
<td height="30" colspan="2" class="upper_bold_green_big"><div align="center">ค้นหาสินค้า</div></td>
</tr>
<tr>
<td width="30%" height="25" class="upper_bold_green2"><div align="left">ยี่ห้อ</div></td>
<td width="70%" height="25"><select name="ssid_brand" class="login_box2" id="ssid_brand">
<option value="">เลือกยี่ห้อทั้งหมด</option>
<?
$rsmain=@mysql_query("select * from brand order by id asc ");
while ($romain=@mysql_fetch_array($rsmain)){
echo "<option value='$romain[id]'";
if ($ssid_brand==$romain[id]){ echo " selected"; }
echo ">".$romain[brand]."</option>";
}
?>
</select></td>
</tr>
<tr>
<td height="25" class="upper_bold_green2"><div align="left">รุ่น</div></td>
<td height="25"><select name="ssid_generation" class="login_box2" id="ssid_generation">
<option value="">เลือกรุ่นทั้งหมด</option>
<?
$rsmain=@mysql_query("select * from generation order by id asc ");
while ($romain=@mysql_fetch_array($rsmain)){
echo "<option value='$romain[id]'";
if ($ssid_generation==$romain[id]){ echo " selected"; }
echo ">".$romain[generation]."</option>";
}
?>
</select></td>
</tr>
<tr>
<td height="25" class="upper_bold_green2"><div align="left">สี</div></td>
<td height="25">
<select name="ssid_color" class="login_box2" id="ssid_color">
<option value="">เลือกสีทั้งหมด</option>
<?
$rsmain=@mysql_query("select * from color order by id asc ");
while ($romain=@mysql_fetch_array($rsmain)){
echo "<option value='$romain[id]'";
if ($ssid_color==$romain[id]){ echo " selected"; }
echo ">".$romain[color]."</option>";
}
?>
</select></td>
</tr>
<tr>
<td height="25" class="upper_bold_green2"><div align="left">ราคาสินค้า</div></td>
<td height="25"><input name="ssprice_a" type="text" class="login_box2" id="ssprice_a" size="6" value="<?=$ssprice_a;?>"/>
-
<input name="ssprice_b" type="text" class="login_box2" id="ssprice_b" size="6" value="<?=$ssprice_b;?>" />
บาท</td>
</tr>
<tr>
<td class="upper_bold_green2"><div align="left"><span class="flinknews">เดือน</span></div></td>
<td><label>
<select name="mmonth" class="login_box2" id="mmonth">
<option value="">เลือกเดือนทั้งหมด</option>
<?
$rsmain=@mysql_query("select * from sys_month order by id asc ");
while ($romain=@mysql_fetch_array($rsmain)){
echo "<option value='$romain[monthStr]'";
if ($mmonth==$romain[monthStr]){ echo " selected"; }
echo ">".$romain[monthTxt]."</option>";
}
?>
</select>
<select name="myear" class="login_box2" id="myear">
<option value="">เลือกปีทั้งหมด</option>
<?
$rsmain=@mysql_query("select * from sys_year order by id asc ");
while ($romain=@mysql_fetch_array($rsmain)){
echo "<option value='$romain[yearCK]'";
if ($myear==$romain[yearCK]){ echo " selected"; }
echo ">".$romain[year]."</option>";
}
?>
</select>
</label></td>
</tr>
<tr>
<td class="upper_bold_green2"> </td>
<td>
<div align="left">
<input name="Submit2" type="submit" class="upper_bold_green2" value="ค้นหาข้อมูล" />
</div></td>
</tr>
<tr>
<td class="upper_bold_green2"> </td>
<td> </td>
</tr>
</table>
</form>
</div></td>
</tr><form action="list_productCheck.php" method="get" enctype="application/x-www-form-urlencoded" target="_top">
<tr>
<td colspan="5" valign="top" bgcolor="#E4F3FA"><div align="center">
<input name="button2" type="submit" class="upper_bold_green_big" id="button2" value="เปรียบเทียบข้อมูลสินค้า" />
<br />
<span class="style113">* เลือกข้อมูลอย่างน้อย 2 รายการเพื่อเปรียบเทียบข้อมูล</span></div></td>
</tr>
<tr>
<?
$total_sum=0;
$total_num=0;
if (empty($recstart)){
$recstart=0;
}
$recperpage=10;
$sql = "select * from product where status='y' and num!='0' $qsearch1 $qsearch2 $qsearch3 $qsearch4 $qsearch5 $qsearch6 order by id desc limit $recstart,$recperpage;";
$result = mysql_query($sql);
echo ($sql);
While($row= mysql_fetch_array($result)){
$id= $row['id'];
$id_member = $row['id_member'];
$id_brand = $row['id_brand'];
$id_generation = $row['id_generation'];
$id_color = $row['id_color'];
$name = $row['name'];
$tuner = $row['tuner'];
$playdisk = $row['playdisk'];
$speaker = $row['speaker'];
$weight = $row['weight'];
$price = $row['price'];
$num = $row['num'];
$photo = $row['photo'];
$status = $row['status'];
$dateproduct = $row['dateproduct'];
$ckMoney = $row['ckMoney'];
$sql2 = "select * from member where id='$id_member'";
$result2= mysql_query($sql2);
While($row2= mysql_fetch_array($result2)){
$prefix= $row2['prefix'];
$fname= $row2['fname'];
$lname= $row2['lname'];
$company= $row2['company'];
}
$sqlcolor= "select * from color where id='$id_color'";
$resultcolor= mysql_query($sqlcolor);
While($rowcolor= mysql_fetch_array($resultcolor)){
$color= $rowcolor['color'];
}
$sql3= "select * from generation where id='$id_generation'";
$result3= mysql_query($sql3);
While($row3= mysql_fetch_array($result3)){
$generation= $row3['generation'];
}
$sql5= "select * from brand where id='$id_brand'";
$result5= mysql_query($sql5);
While($row5= mysql_fetch_array($result5)){
$brand= $row5['brand'];
}
$total_sum++;
?>
<td width="20%" valign="top" bgcolor="#FFF9F4">
<div align="left">
<table width="142" border="0" cellpadding="1" cellspacing="1" bgcolor="#FFF2E8">
<tr>
<td width="100%"><div align="center">
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#FFCCFF">
<tr>
<td><a href="list_shopDetail.php?id=<?=$id;?>" ><img src="resize_jpg.php?w=130&h=150&img=<?=$photo;?>" width="96" height="110" border="0" /></a></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="130" valign="top"><p><span class="body_small_text2">
<?php if (($_SESSION['username'] != "")and ($_SESSION['type_user'] == "2")){ ?>
<br />
<a href="order_add.php?id=<?=$id;?>"><img src="images/m_cart.gif" width="22" height="22" border="0" /><span class="upper_bold_green1"> <img src="images/button_buy_now.gif" width="45" height="14" border="0" /></span></a>
<br />
<? } ?>
<input name="Data1[]" type="checkbox" id="Data1[]" value="<?=$id;?>" />
<?=$name;?>
<br />
</span><span class="body_small_text">รุ่น:
<?=$generation;?>
<br />
สี:
<?=$color;?>
<br />
จำนวน:
<?=$num;?>
เครื่อง<br />
ราคา:
<? $price_number = number_format($price); ?>
<?=$price_number;?>
บาท<br />
</span><span class="body_small_text">ฝากขาย
<?=$dateproduct;?>
</span></p>
</td>
</tr>
</table>
</div></td><? if($total_sum%5==0) { echo '</tr><tr>';
}
$total_num++;
}
?>
</tr></form>
</table>
<div align="right">
<span class="fbottom">จำนวนสินค้า
<?
$hip_sh1=@mysql_query("select count(id) AS num2 from product where status='y' and num!='0' $qsearch1 $qsearch2 $qsearch3 $qsearch4 $qsearch5 $qsearch6 ");
$ada_sh1=@mysql_num_rows($hip_sh1);
while ($ro_sh1=@mysql_fetch_array($hip_sh1)){
$member1=$ro_sh1[num2];
echo "$member1 ";
}
?>
รายการ </span> </div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="30" bgcolor="#FFC697"><div align="center"><span class="taho_green_bold">
<?
// query ข้อมูลจาก database
//จำนวนหน้า
$totrec=@mysql_num_rows(@mysql_query("select id from product where status='y' and num!='0' $qsearch1 $qsearch2 $qsearch3 $qsearch4 $qsearch5 $qsearch6 order by id asc"));
if ($totrec>$recperpage){
$prev=$recstart-$recperpage;
$next=$recstart+$recperpage;
echo " <b><span class='big_bold_bodytexts'>หน้า : </span>";
if (!$recstart==0){
echo "<a href='".$PHP_SELF."?recstart=".$prev."&qsearch1=$qsearch1&qsearch2=$qsearch2&qsearch3=$qsearch3&qsearch4=$qsearch4&qsearch5=$qsearch5&qsearch6=$qsearch6' class='taho_red13'><<</a> ";
} else {
}
for ($i=1; $i<=ceil($totrec/$recperpage);$i++){
if ((($recstart/$recperpage)+1)==$i){
echo "[";
echo $i."";
echo "] ";
} else {
$recstartval=($i-1)*$recperpage;
echo "<a href='".$PHP_SELF."?recstart=".$recstartval."&qsearch1=$qsearch1&qsearch2=$qsearch2&qsearch3=$qsearch3&qsearch4=$qsearch4&qsearch5=$qsearch5&qsearch6=$qsearch6' class='taho_red13'>[".$i."]</a> ";
}
}
if ($recstart<($totrec-$recperpage)){
echo "<a href='".$PHP_SELF."?recstart=".$next."&qsearch1=$qsearch1&qsearch2=$qsearch2&qsearch3=$qsearch3&qsearch4=$qsearch4&qsearch5=$qsearch5&qsearch6=$qsearch6' class='taho_red13'>>></a>";
} else {
}
echo "</b>";
}
?>
</span><?
if ($member1==0)
{
echo "<strong> <font color='red'>ไม่พบข้อมูลที่ค้นหา </font></strong>";
}
?>
</div></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0">
<tr>
<td width="100%"><hr /></td>
</tr>
</table>
</div></td>
</tr>
</table>
<!-- InstanceEndEditable --></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="40" background="images/foot5.jpg"><div align="center" class="menu"><span class="style6"><strong>จำนวนผู้เข้าชมเว็บ
<?
$wash_couter=@mysql_num_rows(@mysql_query("select id from counter order by id asc"));
?><?=$wash_couter;?>
ครั้ง ::COPIER :: Home Theater Online</strong></span><strong><br />
<span class="style6"> ระบบการเลือกซื้อชุดโฮมเธียเตอร์และฝากขายชุดโฮมเทียเตอร์</span></strong><br />
</div></td>
</tr>
</table></td>
</tr>
</table>
</div>
</body>
<!-- InstanceEnd --></html>
Date :
2011-08-17 08:06:21
By :
nuntza
อันนี้เป็นโค้ดทั้งหมดครับ
หน้าแรกมันก็ select * from product where status='y' and num!='0' and(ckMoney='08-2011') order by id desc limit 0,10; ได้ปกตินะครับ
หรือว่าเป็นที่ตรงนี้ครับ
if (($mmonth!="") and ($myear!="")) {
$ckmy="$mmonth-$myear";
$qsearch6="and(ckMoney='$ckmy')";
}
Date :
2011-08-17 08:10:05
By :
nuntza
Load balance : Server 05