|
 |
|
แสดงสินค้าหลายหน้า แบบแยกประเภทสินค้า แบบนี้อ่ะ [1] [2] [3] [4] สมมติเลือกประเภทอุปกรณ์ตกแต่งแล้วมีสินค้าเกิน1หน้า ... |
|
 |
|
|
 |
 |
|
แสดงสินค้าหลายหน้า แบบแยกประเภทสินค้า แบบนี้อ่ะ [1] [2] [3] [4] สมมติเลือกประเภทอุปกรณ์ตกแต่งแล้วมีสินค้าเกิน1หน้า แต่เมื่อคลิกหน้า2หรือ3หรือ4ก็จะกลับมาหน้าแรกของเวปทุกที ซึ่งหน้าแรกเป็นหน้ารวมสินค้าไล่ลำดับจากการแอดสินค้าเข้าไป ช่วยดูทีครับ มีโค๊ดมาด้วย
ช่วยดูให้หน่อยนะครับ ขอบคุณครับ
<?
}
else if($type!='')
{
$cmd = "select * from product where cate_id = '$type' and pro_status !='del' LIMIT $offset,$rowsPerPage ";
$result_pro = mysql_query($cmd,$link); $number=mysql_num_rows($result_pro) ;
}
else if($type=='')
{
$cmd = "select * from product where pro_status !='del' ORDER BY pro_auto DESC LIMIT $offset,$rowsPerPage";
$result_pro = mysql_query($cmd,$link); $number=mysql_num_rows($result_pro) ;
}
if($type != ""){$query = "SELECT COUNT(pro_auto) AS numrows FROM product where cate_id = '$type' and pro_status !='del' ORDER BY pro_auto ASC ";}
else{$query = "SELECT COUNT(pro_auto) AS numrows FROM product where pro_status !='del' ORDER BY pro_auto ASC ";}
if($word != ""){$query = "SELECT COUNT(pro_auto) AS numrows FROM product where pro_name like '%$word%' and pro_status !='del' ORDER BY pro_auto ASC ";}
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);//หน้าสุดท้าย
$self = $_SERVER['PHP_SELF'];
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"index?menu=&page=$page&word=$word&index=$index&y=1&pname=$pname \">[ย้อนกลับ]</a> ";
$first = " <a href=\"index?menu=&page=1&word=$word&index=$index&y=1&pname=$pname \">[หน้าแรก]</a> ";
}
else
{
$prev = ' [ย้อนกลับ] '; // we're on page one, don't enable 'previous' link
$first = ' [หน้าแรก] '; // nor 'first page' link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"index?menu=&page=$page&word=$word&index=$index&y=1&pname=$pname \">[ถัดไป]</a> ";
$last = " <a href=\"index?menu=&page=$maxPage&word=$word&index=$index&y=1&pname=$pname \">[หน้าสุดท้าย]</a> ";
for($i=0;$i<4;$i++)
{
$lastz[$i] = $pageNum-$i;
}
}
else
{
$next = ' [ถัดไป] '; // we're on the last page, don't enable 'next' link
$last = ' [หน้าสุดท้าย] '; // nor 'last page' link
}
for($i=$pageNum;$i<=($pageNum+5);$i++)
{
if($i<$maxPage){$firstz[$i] = "<a href=\"index?menu=&page=$i&word=$word&index=$index&y=1&pname=$pname \">[$i]</a> ";}
else if($i==$maxPage){
for($j=$maxPage;$j>=($maxPage-5);$j--)
{
if($j>0){$firstz[$j] = "<a href=\"index?menu=&page=$j&word=$word&index=$index&y=1&pname=$pname \">[$j]</a> ";}
}
}
}
echo $first . $prev."--- ";
for($i=0;$i<=1000;$i++)
{
echo $firstz[$i];
}
echo " ---".$next . $last;
echo"<BR>หน้าที่ <strong>$pageNum</strong> จาก <strong>$maxPage</strong> หน้า ( จำนวน<strong> $number </strong> รายการ )";
?>
Tag : PHP, MySQL, CakePHP

|
|
 |
 |
 |
 |
Date :
2011-04-13 12:50:51 |
By :
Chupong |
View :
2633 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค๊ดตัวนี้สามารถใช้ได้ดีเลยครับแต่ต้องแสดงรายการที่ไม่ได้แยกประเภท
ส่วนในหน้าสินค้าของผมจะเป็นแบบ แยกตามประเภทสินค้า เมื่อคลิกเลือกประเภทก็จะมีแต่สินค้าประเภทนั้นๆ แล้วคลิกหน้าต่อไปของสินค้าประเภทที่เลือกมันจะเด้งกลับมาหน้าแรก คือหน้าแสดงสินค้ารวม
เช่น index?type=C1001 เป็นสินค้าประเภทแรก
แล้ว index?type=C1002 เป็นประเภทที่สอง
และ ในหน้า index.php จะแสดงสินค้าทุกประเภทตามลำดับการaddสินค้า
|
 |
 |
 |
 |
Date :
2011-04-13 13:22:18 |
By :
Chupong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แว้วว
|
 |
 |
 |
 |
Date :
2011-04-13 19:20:09 |
By :
Chupong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|