อาจารย์ช่วยด้วยครับ แบ่งหน้าแบบมีเงื่อนไขอะครับ

คือว่าผมจะ query ข้อมูลจาก ฐานข้อมูล โดย join table document กับ document_type อะครับ แล้วผมต้องการแบ่งหน้าตามข้อมูลที่แสดงตามประเภทเอกสารอะครับ เวลากด next หมวดที่ 1 ไป page อื่น หมวดที่ 2 มันเปลี่ยนด้วยอะครับ คือผมไม่อยากให้หมวดอื่นเปลี่ยน ตามอะครับ ช่วยผมด้วยน่ะครับ อาจารย์ ขอบคุณครับ
16 มิ.ย. 2552 4 3,142

ตอนกำหนด link สำหรับการแบ่งหน้าให้ส่งหมวดไปด้วยสิครับ เช่น

index.php?page=&category=1

มันก็นำหมวดไป query ด้วยได้
#1

ไม่ได้เลยครับอาจารย์ ใส่หมวดไปด้วยแล้ว ก็ยังเหมือนเดิมครับ ช่วยดูให้หน่อยน่ะครับผม
include("connect.php");
$d=date("d/m");
$y=date("Y")+543;
$dy="$d/$y";
$sql="SELECT
document_recive.doc_no,
document_recive.doc_regis,
document_recive.depart_recive,
document_recive.date_recive,
document_recive.time_recive,
document_recive.`status`,
document_recive.id,
document_recive.user_recive,
document.doc_id,
document.doc_date,document.doc_type,
document.desciption,document.doc_from
FROM
document_recive
Inner Join document ON document_recive.doc_no = document.doc_no";
//if($_GET['dts']=="") {
$sql.=" WHERE mid(document_recive.doc_regis,1,1) = '$doc_type_no'";// where เอกสารลงรับโดยแยกตามประเภทเอกสาร
$sql.=" OR mid(document_recive.doc_regis,1,1) = '$_GET[doctypepage]'";

$sql.=" order by CAST(document_recive.id AS SIGNED) DESC";
$Per_Page =10;
if(!$Page)
$Page=1;
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$result = mysql_query($sql);
$Page_start = ($Per_Page*$Page)-$Per_Page;
$Num_Rows = mysql_num_rows($result);
if($Num_Rows<=$Per_Page)
$Num_Pages =1;
else if(($Num_Rows % $Per_Page)==0)
$Num_Pages =($Num_Rows/$Per_Page) ;
else
$Num_Pages =($Num_Rows/$Per_Page) +1;
$Num_Pages = (int)$Num_Pages;
$sql.=" LIMIT $Page_start , $Per_Page";
$result=mysql_query($sql);   
$numrows=mysql_num_rows($result);
           
while($n=mysql_fetch_array($result)) {

echo "--------------";

//-------next page-----------
if($Prev_Page)
echo " <a href='$PHP_SELF?Page=$Prev_Page'><< ย้อนกลับ </a>";
for($i=1; $i<$Num_Pages; $i++){
if($i != $Page)
echo "[<a href='$PHP_SELF?Page=$i&doctypepage$doctype'>$i</a>]";//-------------- ส่งประเภทเอกสารไปด้วย
else
echo "<b> $i </b>";
}
/*สร้างปุ่มเดินหน้า */
if($Page!=$Num_Pages)
echo "<a href ='$PHP_SELF?Page=$Next_Page'> หน้าถัดไป>> </a>";
//------------- end----------------------
#2

อ่านะ หมวด ส่งไปเฉยๆ แต่ไม่เอาไปใส่ใน query มันจะมีประโยชน์อะไร

<?php
$page = (int)$_GET[page];
$category= (int)$_GET[category]; // รับหมวดมา

$sql = "SELECT * FROM ..... WHERE category=$category ........"; // query

echo '<a href="index.php?page='.$i.'&amp;category='.$category.'">'.$i.'</a>'; // โค้ดแบ่งหน้า
?>
#3

ขอบคุณครับอาจารย์ ขอรบกวนอีกครั้งน่ะครับผม พอดีมันยังไม่ได้อะครับ
คือว่า ผม query สองครั้ง ครั้งที่ 1 query เอาเฉพาะประเภทเอกสาร
<?
// query เอาประเภทเอกสาร
$doctype_sql="select * from document_recive inner join document_type on mid(document_recive.doc_regis,1,1)=document_type.doc_no_type where document_recive.depart_recive='$_SESSION[depart]' ";
          $doctype_sql.=" group by mid(document_recive.doc_regis,1,1)";
          $doctype_result=mysql_query($doctype_sql);
echo "<table>......................";
while($fechtdoc=mysql_fetch_array($doctype_result)) {
         $doc_type_no=$fechtdoc['doc_no_type'];//------ประเภทเอกสาร
?>
//------query ครั้งที่ 2 query เอารายการเอกสารทั้งหมด แสดงตามเงื่อนไข
<?
$sql="SELECT
document_recive.doc_no,
document_recive.doc_regis,
document_recive.depart_recive,
document_recive.date_recive,
document_recive.time_recive,
document_recive.`status`,
document_recive.id,
document_recive.user_recive,
document.doc_id,
document.doc_date,document.doc_type,
document.desciption,document.doc_from
FROM
document_recive
Inner Join document ON document_recive.doc_no = document.doc_no";

$_GET['Page'];
$_GET['pagetype'];

if($_GET['pagetype'] =="") {
$sql.=" WHERE mid(document_recive.doc_regis,1,1) = '$doc_type_no'";// where เอกสารลงรับโดยแยกตามประเภทเอกสาร
} else {
$sql.=" WHERE mid(document_recive.doc_regis,1,1) = '$pagetype'";
       }
$sql.=" order by CAST(document_recive.id AS SIGNED) DESC";
//-----------กำหนดแสดงหน้า
$Per_Page =10;
if(!$Page)
$Page=1;
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$result = mysql_query($sql);
$Page_start = ($Per_Page*$Page)-$Per_Page;
$Num_Rows = mysql_num_rows($result);
if($Num_Rows<=$Per_Page)
$Num_Pages =1;
else if(($Num_Rows % $Per_Page)==0)
$Num_Pages =($Num_Rows/$Per_Page) ;
else
$Num_Pages =($Num_Rows/$Per_Page) +1;
$Num_Pages = (int)$Num_Pages;
$sql.=" LIMIT $Page_start , $Per_Page";
$result=mysql_query($sql);   
$numrows=mysql_num_rows($result);
           
while($n=mysql_fetch_array($result)) {
echo "........รายการเอกสารที่แสดงตามประเภทเอกสาร..........................";
      } ปิดรูปรายการเอกสารแสดงตามประเภทเอกสาร
echo "</table>";
} // ปิดรูปประเภทเอกสาร
?>
//--------------------------------next page--------------
<? /* สร้างปุ่มย้อนกลับ */

if($Prev_Page)
echo " <a href='$PHP_SELF?Page=$Prev_Page'><< ย้อนกลับ </a>";
for($i=1; $i<$Num_Pages; $i++){
if($i != $Page)
//echo '[<a href="$PHP_SELF?Page='.$i.'&amp;pagetype='.$doc_type_no.'">'.$i.'</a>]'; // โค้ดแบ่งหน้า
echo "[<a href='$PHP_SELF?Page=$i&amp;pagetype=$doc_type_no&amp;next2=$next1'>$i</a>]";//-------------- ส่งประเภทเอกสารไปด้วย
else
echo "<b> $i </b>";
}
/*สร้างปุ่มเดินหน้า */
if($Page!=$Num_Pages)
echo "<a href ='$PHP_SELF?Page=$Next_Page'> หน้าถัดไป>> </a>";

?>
ขอรบกวนอีกครั้งน่ะครับผมอาจารย์ ขอบคุณครับ
#4
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^