|
 |
|
การแบ่งหน้าค่ะ ถามเรื่องแบ่งหน้าอ่าพี่คือว่ามานเปงเวปซื้อขายสินค้าอ่าพี่แล้วลูกค้าต้องเลือกประเภทสินค้าที่ต้องการดู |
|
 |
|
|
 |
 |
|
ลองดูครับว่าได้หรือป่าวครับ
คือผมให้มันส่งค่า $type ไปใน link next page ด้วยอะครับ
<form method="post" name="form_test">
<?
$type = $_REQUEST['type'];
if(!isset($start)){
$start = 0;
}
$limit = '10'; // แสดงผลหน้าละกี่หัวข้อ
/* หาจำนวน record ทั้งหมด
ปล. อันนี้ต้องใช้กับตัวแบ่งนะ ห้ามเอาออก*/
$Qtotal = mysql_query("select * from Product where ID_Type = '$type' "); //คิวรี่ คำสั่ง
$total = mysql_num_rows($Qtotal); // หาจำนวน record
/* คิวรี่ข้อมูลออกมาเพื่อแสดงผล */
$Query = mysql_query("select * from Product where ID_Type = '$type' ORDER BY ID_Pro DESC LIMIT $start,$limit"); //คิวรี่คำสั่ง
$totalp = mysql_num_rows($Query); // หาจำนวน record ที่เรียกออกมา
$intRows = 0;
$sql = mysql_query("select * from typepro");
?>
<table width="950" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td colspan="2" align="right"><span class="normal13blueBold">เลือกประเภทสินค้า:</span> </td>
<td colspan="2">
<select name="type" id="type" onChange="submit_click(this.form,'type')" >
<option >---Choose Type---</option>
<? while($result = mysql_fetch_array($sql)){?>
<option value="<? echo $result['ID_Type'] ?>"><? echo $result['Name_Type']?></option>
<? } ?>
</select></td>
</tr>
<tr>
<td> </td>
<td align="left" valign="top"> </td>
<td> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<?
while($arr = mysql_fetch_array($Query)){
$intRows++;
echo "<td>";
?>
<table width="91" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><a href="admin/Product/images_product/<?=$arr["Image_Pro"];?>" target="_blank"><img src="admin/Product/images_product/<?=$arr["Image_Pro"];?>" width="100" height="100" border="0"></a></div></td>
</tr>
<tr>
<td><div align="left"><span class="narmal3old"><?=$arr["Name_Pro"];?></span></div></td>
</tr>
<tr>
<td><div align="left"><span class="narmal3old">Price: <?=$arr["Price_Pro"];?> BATH</span></div></td>
</tr>
<tr>
<td><div align="left"><span class="narmal3old">Color: <?=$arr["Color_Pro"];?></span></div></td>
</tr>
<tr>
<td ><div align="left"><span class="narmal3old">Size: <?=$arr["Size_Pro"];?></span></div></td>
</tr>
</table>
<?
echo"</td>";
if(($intRows)%5==0)
{
echo"</tr>";
}
else
{
echo "<td>";
}
}
//echo"</tr></table>";
?>
</tr>
<tr>
<td height="10" colspan="4"></td>
</tr>
<tr>
<td height="10" colspan="4"></td>
</tr>
<tr>
<td height="10" colspan="4"></td>
</tr>
<tr>
<td height="10" colspan="4"></td>
</tr>
<tr>
<td height="10" colspan="4"></td>
</tr>
<tr>
<td height="10" colspan="4"></td>
</tr>
<tr>
<td height="10" colspan="4"></td>
</tr>
<tr>
<td height="10" colspan="4"></td>
</tr>
</table>
<?
$page = ceil($total/$limit); // เอา record ทั้งหมด หารด้วย จำนวนที่จะแสดงของแต่ละหน้า
/* เอาผลหาร มาวน เป็นตัวเลข เรียงกัน เช่น สมมุติว่าหารได้ 3 เอามาวลก็จะได้ 1 2 3 */
for($i=1;$i<=$page;$i++){
if($_REQUEST['page']==$i){ //ถ้าตัวแปล page ตรง กับ เลขที่วนได้
echo "[<a href='?start=".$limit*($i-1)."&page=$i&type=".$type."'><B>$i</B></A>]"; //ลิ้งค์ แบ่งหน้า เงื่อนไขที่ 1
}else{
echo "[<a href='?start=".$limit*($i-1)."&page=$i&type=".$type."'>$i</A>]"; //ลิ้งค์ แบ่งหน้า เงื่อนไขที่ 2
}
}
?>
</form>
<Script language="javascript">
function submit_click(obj,s)
{
if(s=='type' & document.form_test.type.value!='<?=$type?>')
{
obj.action="";
obj.submit();
}
}
</Script>
|
 |
 |
 |
 |
Date :
2010-03-02 13:48:21 |
By :
windersun |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เย้ๆ ขอบคุณมากค่ะ^^
|
 |
 |
 |
 |
Date :
2010-03-03 09:59:08 |
By :
LuckyStar |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|