<? if(!isset($_GET[start])){ $start = 0; }else{ $start = $_GET[start]; } $limit = '10'; // แสดงผลหน้าละกี่หัวข้อ if($_GET[cat_id]){ $con=" where cat_id='$_GET[cat_id]' "; } $query_all=mysql_query("select * from product $con"); $total =mysql_num_rows($query_all); $pageDispay = ceil($total/$limit); ?> <table width="100%" border="0"> <tr> <td width="24%"><? if($_GET[page]>1){ $pageb=$_GET[page]-1; $startb=$limit*($pageb-1); echo "<a href='?type=$_GET[type]&start=$startb&page=$pageb'>กลับหน้าเดิม</A>"; }else{?> <a href="index.php">กลับหน้าหลัก</a> <? }?></td> <td width="76%"><table width="100%" border="0" align="center"> <tr> <td align="right"> <? for($i=1;$i<=$pageDispay ;$i++){ if($_GET['page']==$i){ //ถ้าตัวแปล page ตรง กับ เลขที่วนได้ echo "[<a href='?type=$_GET[type]&start=".$limit*($i-1)."&page=$i'><B>$i</B></A>]"; //ลิ้งค์ แบ่งหน้า เงื่อนไขที่ 1 }else{ echo "[<a href='?type=$_GET[type]&start=".$limit*($i-1)."&page=$i'>$i</A>]"; //ลิ้งค์ แบ่งหน้า เงื่อนไขที่ 2 } } ?></td> </tr> </table></td> </tr> </table> <br /> <table width="100%" border="1" align="center" cellpadding="0" cellspacing="0"> <td width="100%" height="30" align="center" border="1" bgcolor="#D6D6D6"><strong>รายการสินค้า</strong></td> </tr> </table> <table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#D6D6D6"> <tr> <? $sqlpd="select * from product $con order by pro_id desc LIMIT $start,$limit "; $querypd=mysql_query($sqlpd); $numpd=mysql_num_rows($querypd); if($numpd>0){ while($rspd=mysql_fetch_array($querypd)){ $querypm=mysql_query("select * from promotion where pro_id='$rspd[pro_id]'"); $num_promo=mysql_num_rows($querypm); if($num_promo>0){ $rspm=mysql_fetch_array($querypm); } $b++; ?> <tr> <td><table width="100%" border="1" cellpadding="0" cellspacing="0" style="border:solid 1px;"> <tr> <td height="30" colspan="2" class="size12" style="padding-left:5px;"><span class="style5 style1"><strong><?php echo $rspd[pro_name]; ?> </strong></span></td> </tr> <tr> <td width="89" valign="top" class="pad5" style="text-align:center;"><div><a href="pd_img/<?php echo $rspd[pro_image ]; ?>"><img src="pd_img/<?php echo $rspd[pro_image ]; ?>" alt="" width="80" height="80" border="1" /></a></div><? if($num_promo<=0){ ?> <div style="margin-top:5px;" class="size11"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><span class="size11" style="margin-top:5px;">สั่งซื้อ</span></td> <td><span class="size11" style="margin-top:5px;"> <input name="<?php echo $rspd[prom_id]; ?>" type="text" id="<?php echo $rspd[pro_id]; ?>" style="width:30px; border:solid 1px; text-align:center" value="1" maxlength="3"/> </span></td> <td><a href="#" onclick="selectProduct('<?php echo $rspd[pro_id];?>'); return false;"><img src="images/ok.gif" width="20" height="20" border="0" /></a></td> </tr> </table> </div> <? }else{?> <div style="margin-top:5px;" class="size11"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><span class="size11" style="margin-top:5px;">สั่งซื้อ</span></td> <td><span class="size11" style="margin-top:5px;"> <input name="<?php echo $rspm[prom_id]; ?>p" type="text" id="<?php echo $rspm[prom_id]; ?>p" style="width:30px; border:solid 1px; text-align:center" value="1" maxlength="3"/> </span></td> <td><a href="#" onclick="selectProduct('<?php echo $rspm[prom_id];?>p'); return false;"><img src="images/ok.gif" width="20" height="20" border="0" /></a></td> </tr> </table> <a href="#" onclick="selectProduct('<?php echo $rspd[prom_id];?>p')"></a></div> <? }?></td> <td width="404" height="90" valign="top" class="size12 pad5"><?php echo $rspd[pro_detail]; ?> <div> </div> <div> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50"><img src="images/priceStd.jpg" width="50" height="18" alt="" /></td> <td valign="top"> <font color="#0000FF"><?php echo $rspd[pro_price]; ?></font> บ.</td> </tr> </table> </div> <? if($num_promo>0){ ?> <div> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50"><img src="images/disCount.jpg" width="50" height="18" alt="" /></td> <td valign="top"> <font color="#FF0000"><?php echo $rspm[prom_price]; ?></font> บ.</td> </tr> </table> </div> <? }?> <div> </div> <div align="right"></div></td> </tr> </table></td></tr><tr><td colspan="2"> </td></tr> <? } ?> <? }else{ echo "<tr><td height='30' align='center'><font color='red'>ไม่มีรายการสินค้า</font></td></tr>"; }?> </table>
<html> <head> <title>ThaiCreate.Com PHP & MySQL Tutorial</title> </head> <body> <form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>"> <table width="599" border="1"> <tr> <th>Keyword <input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>"> <input type="submit" value="Search"></th> </tr> </table> </form> <? if($_GET["txtKeyword"] != "") { $objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database"); $objDB = mysql_select_db("mydatabase"); // Search By Name or Email $strSQL = "SELECT * FROM customer WHERE (Name LIKE '%".$_GET["txtKeyword"]."%' or Email LIKE '%".$_GET["txtKeyword"]."%')"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $Num_Rows = mysql_num_rows($objQuery); $Per_Page = 2; // 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_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; } $strSQL .=" order by CustomerID ASC LIMIT $Page_Start , $Per_Page"; $objQuery = mysql_query($strSQL); ?> <table width="600" border="1"> <tr> <th width="91"> <div align="center">CustomerID </div></th> <th width="98"> <div align="center">Name </div></th> <th width="198"> <div align="center">Email </div></th> <th width="97"> <div align="center">CountryCode </div></th> <th width="59"> <div align="center">Budget </div></th> <th width="71"> <div align="center">Used </div></th> </tr> <? while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td><div align="center"><?=$objResult["CustomerID"];?></div></td> <td><?=$objResult["Name"];?></td> <td><?=$objResult["Email"];?></td> <td><div align="center"><?=$objResult["CountryCode"];?></div></td> <td align="right"><?=$objResult["Budget"];?></td> <td align="right"><?=$objResult["Used"];?></td> </tr> <? } ?> </table> <br> Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page : <? if($Prev_Page) { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a> "; } for($i=1; $i<=$Num_Pages; $i++){ if($i != $Page) { echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]"; } else { echo "<b> $i </b>"; } } if($Page!=$Num_Pages) { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtKeyword=$_GET[txtKeyword]'>Next>></a> "; } mysql_close($objConnect); } ?> </body> </html>
SELECT Column1,Column2,Column3,... FROM [Table-Name] WHERE [Field] BETWEEN [Value-Start] AND [Value-End]
SELECT * FROM customer WHERE Budget BETWEEN '1000000' AND '3000000'
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง