<?php if (($keyword=="") || ($fields=="")) { echo "กรุณาเลือกรายการค้นหา"; } else { $objConn=mysql_connect("localhost","root","1234") or die("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ "); mysql_select_db(stock) or die("เลือกฐานข้อมูลไม่ได้"); $sql=" SELECT * FROM product WHERE $fields like '%$keyword%' "; $db_query=mysql_db_query($db,$sql); $num_rows=mysql_num_rows($db_query); $Per_Page = 3; // Per Page $Page = $_GET["Page"]; if(!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($num_nows<=$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 .=" ORDER BY pro_id ASC LIMIT $Page_Start , $Per_Page"; $db_query=mysql_db_query($db,$sql); if(!$result){ echo mysql_error(); } if(empty($num_rows)) { echo"<center>ไม่พบข้อมูล <b> $keyword </b> จากฐานข้อมูล </center>"; } else { ?> </p> <p><? echo " แสดงรายการค้นหา <b> $keyword </b> จากฐานข้อมูลพบ <b> $num_rows </b> รายการ "; ?></p> <table width="890" border="1" align="center"> <tr> <td width="32" height="30" align="center">No.</td> <td width="99" height="30" align="center" >รหัสสินค้า</td> <td width="212" height="30" align="center">ชื่อสินค้า</td> <td width="100" height="30" align="center">ต้นทุน</td> <td width="100" height="30" align="center">ราคาขาย</td> <td width="100" height="30" align="center">สินค้าคงคลัง</td> <td width="100" height="30" align="center">ผู้จัดจำหน่าย</td> <td width="95" height="30" align="center">แก้ไข/ลบ</td> </tr> </table> <? $a=1; while ($result = mysql_fetch_array($db_query)) { ?> <table width="890" border="1" align="center" cellpadding="0" cellspacing="1"> <tr> <td width="33" height="28"><div align="center"><? echo $a; ?></div></td> <td width="90" height="28" ><div align="center"><? echo $result["pro_id"];?></div></td> <td width="195" height="28"><? echo $result["pro_name"]; ?></td> <td width="93" height="28"><div align="center"><? echo $result["pro_cost"];?></div></td> <td width="93" height="28"><div align="center"><? echo $result["pro_saleprice"];?></div></td> <td width="93" height="28"><div align="center"><? echo $result["pro_amount"];?></div></td> <td width="93" height="28"><div align="center"><? echo $result["sup_id"];?></div></td> <td width="83" height="28" align="center"><a href="pd_edit.php?pro_id=<?echo"$pro_id"; ?> " onclick="return confirm('คุณต้องการจะแก้ไขรายการ?')">แก้ไข <a href="pd_del.php?pro_id=<?echo"$pro_id";?>" onclick="return confirm('คุณต้องการจะลบรายการ?')">ลบ </a> </div></td> </tr> </table> <? $a++; } } } ?> <p>Total <?php echo $num_rows;?> Record : <?php echo $Num_Pages;?> Page : <?php if($Prev_Page) { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> "; } for($a=1; $a<=$Num_Pages; $a++){ if($a != $Page) { echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$a'>$a</a> ]"; } else { echo "<b> $a </b>"; } } if($Page!=$Num_Pages) { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> "; } ?></p> </form> <p> </p> <p> </p></td> </tr> </table>
Quote:if($num_nows<=$Per_Page)
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง