<HTML> <HEAD><TITLE></TITLE><meta http-equiv=Content-Type content="text/html; charset=tis-620"> </HEAD> <BODY> <script language="javascript"> function fncSubmit(strPage) { if(document.form1.rdo1.checked == false && document.form1.rdo2.checked == false ) { alert('Please Click Radio Option '); return false; } document.form1.submit(); } </script> <FORM ACTION="search2.php" METHOD="post" name="form1"onSubmit="JavaScript:return fncSubmit();"> <TABLE WIDTH="400" BORDER="0" CELLSPACING="1" CELLPADDING="0"> <TR> <TD WIDTH="101" align="center" valign="top"><span class="style2">Search</span></TD> <TD align="left" valign="top"><p> <INPUT NAME="type" TYPE="text" id="type" SIZE="40"> * </p> </TD> </TR> <TR> <TD> </TD> <TD align="left" valign="top"><p> <input name="radiobutton" type="radio"id="rdo1" value="1" onClick="document.getElementById('select2').disabled=true;"> ชื่อหอพัก </p> <p> <input name="radiobutton" type="radio"id="rdo2" value="2" onClick="document.getElementById('select2').disabled=false;"> ราคาหอพัก <select name="select" id="select" disabled> <option value="1"selected="selected">น้อยกว่า 1000</option> <option value="2">1001-1500</option> <option value="3">1501-2000</option> <option value="4">2001-2500</option> <option value="5">2501-3000</option> <option value="6">มากกว่า 3000</option> </select> </p> <p> <input name="submit" type="submit" class="button"value="ค้นหา" /> </p></TD> </TR> </TABLE> </FORM> </BODY> </HTML>
$strSQL = "SELECT * FROM customer WHERE 1 "; if($_POST["ddlCountryCode"] != "") { $strSQL .= " AND (CountryCode = '".$_POST["ddlCountryCode"]."') "; } if($_POST["txtKeyword"] != "") { $strSQL .= " AND (Name LIKE '%".$_POST["txtKeyword"]."%' or Email LIKE '%".$_POST["txtKeyword"]."%' ) "; }
<html> <head> <title>ThaiCreate.Com PHP & MySQL Tutorial</title> </head> <body> <form name="frmSearch" method="post" action="<?=$_SERVER['SCRIPT_NAME'];?>"> <table width="599" border="1"> <tr> <th>Country Code <select name="ddlCountryCode" id="ddlCountryCode"> <option>- Select Country Code -</option> <option value="TH">TH</option> <option value="EN">EN</option> <option value="US">US</option> </select> Keyword <input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>"> <input type="submit" value="Search"></th> </tr> </table> </form> <? $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 1 "; if($_POST["ddlCountryCode"] != "") { $strSQL .= " AND (CountryCode = '".$_POST["ddlCountryCode"]."') "; } if($_POST["txtKeyword"] != "") { $strSQL .= " AND (Name LIKE '%".$_POST["txtKeyword"]."%' or Email LIKE '%".$_POST["txtKeyword"]."%' ) "; } $objQuery = mysql_query($strSQL) or die ("Error 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> <? mysql_close($objConnect); ?> </body> </html>
<html> <head> <title>ค้นหา</title> </head> <body> <form name="frmSearch" method="post" action="<?=$_SERVER['SCRIPT_NAME'];?>"> //ต้องเปลี่ยนSCRIPT_NAME ไหมครับ <table width="599" border="1"> <tr> <th>ราคาห้องพัก <select name="ddlCountryCode" id="ddlCountryCode"> <option>- เลือกราคา -</option> <option value="1">น้อยกว่า1000</option> <option value="2">1001-1500</option> <option value="3">1501-2000</option> <option value="1">2001-2500</option> <option value="2">2501-3000</option> <option value="3">มากกว่า 3000</option> </select> ค้นหา <input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>"> <input type="submit" value="Search"></th> </tr> </table> </form> <? include("connect.php"); mysql_select_db( $dbwn )or die ( "ไม่สามารถเลือกใช้งานฐานข้อมูล$dbname" ); ?> <? // Search By Name or Email $strSQL = "SELECT * FROM db_product WHERE 1 "; //where 1 แปลว่าไรหรอครับ if($_POST["ddlCountryCode"] != "") { $strSQL .= " AND (CountryCode = '".$_POST["ddlCountryCode"]."') "; } if($_POST["txtKeyword"] != "") { $strSQL .= " AND (name_prd LIKE '%".$_POST["txtKeyword"]."%' or price_prd '%".$_POST["txtKeyword"]."%' ) "; } $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); ?> <table width="600" border="1"> <tr> <th width="91"> <div align="center">id_prd </div></th> <th width="98"> <div align="center">name_prd </div></th> <th width="198"> <div align="center">ref_id_type </div></th> <th width="97"> <div align="center">detail_prd </div></th> <th width="59"> <div align="center">price_prd </div></th> <th width="71"> <div align="center">photo_prd</div></th> </tr> <? while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td><div align="center"><?=$objResult["id_prd"];?></div></td> <td><?=$objResult["name_prd"];?></td> <td><?=$objResult["ref_id_type"];?></td> <td><div align="center"><?=$objResult["detail_prd"];?></div></td> <td align="right"><?=$objResult["price_prd"];?></td> <td align="right"><?=$objResult["photo_prd"];?></td> </tr> <? } ?> </table> <? mysql_close($objConnect); ?> </body> </html>
<html> <head> <title>ค้นหา</title> </head> <body> <form name="frmSearch" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <table width="599" border="1"> <tr> <th>ราคาห้องพัก <select name="price" id="price"> <option>- เลือกราคา -</option> <option value="1" <? if($price==1){?>selected<? }?>>น้อยกว่า1000</option> <option value="2" <? if($price==2){?>selected<? }?>>1001-1500</option> <option value="3" <? if($price==3){?>selected<? }?>>1501-2000</option> <option value="4" <? if($price==4){?>selected<? }?>>2001-2500</option> <option value="5" <? if($price==5){?>selected<? }?>>2501-3000</option> <option value="6" <? if($price==6){?>selected<? }?>>มากกว่า 3000</option> </select> ค้นหา <input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>"> <input type="submit" value="Search"></th> </tr> </table> </form> <? @include("connect.php"); ?> <? if($_REQUEST['price']!=''){ $price = $_REQUEST['price']; switch($price){ case 1: $where = " WHERE price_prd < 1000 "; break; case 2: $where = " WHERE price_prd BETWEEN 1001 AND 1500 "; break; case 3: $where = " WHERE price_prd BETWEEN 1501 AND 2000 "; break; case 4: $where = " WHERE price_prd BETWEEN 2001 AND 2500 "; break; case 5: $where = " WHERE price_prd BETWEEN 2501 AND 3000 "; break; case 6: $where = " WHERE price_prd > 3000 "; break; } } if($_REQUEST["txtKeyword"] != ""){ $detail = $_REQUEST["txtKeyword"]; $where = " WHERE (detail_prd LIKE '%".$detail."%') "; } if($_REQUEST['price']!='' && $_REQUEST["txtKeyword"] != ""){ $price = $_REQUEST['price']; $detail = $_REQUEST["txtKeyword"]; switch($price){ case 1: $where = " WHERE price_prd < 1000 AND detail_prd LIKE '%".$detail."%' "; break; case 2: $where = " WHERE price_prd BETWEEN 1001 AND 1500 AND detail_prd LIKE '%".$detail."%'"; break; case 3: $where = " WHERE price_prd BETWEEN 1501 AND 2000 AND detail_prd LIKE '%".$detail."%'"; break; case 4: $where = " WHERE price_prd BETWEEN 2001 AND 2500 AND detail_prd LIKE '%".$detail."%'"; break; case 5: $where = " WHERE price_prd BETWEEN 2501 AND 3000 AND detail_prd LIKE '%".$detail."%'"; break; case 6: $where = " WHERE price_prd > 3000 AND detail_prd LIKE '%".$detail."%'"; break; } } else{ $where = " price_prd > 0"; } $strSQL = "SELECT * FROM db_product $where "; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); ?> <table width="600" border="1"> <tr> <th width="91"> <div align="center">id_prd </div></th> <th width="98"> <div align="center">name_prd </div></th> <th width="198"> <div align="center">ref_id_type </div></th> <th width="97"> <div align="center">detail_prd </div></th> <th width="59"> <div align="center">price_prd </div></th> <th width="71"> <div align="center">photo_prd</div></th> </tr> <? while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td><div align="center"><?=$objResult["id_prd"];?></div></td> <td><?=$objResult["name_prd"];?></td> <td><?=$objResult["ref_id_type"];?></td> <td><div align="center"><?=$objResult["detail_prd"];?></div></td> <td align="right"><?=$objResult["price_prd"];?></td> <td align="right"><?=$objResult["photo_prd"];?></td> </tr> <? } ?> </table> <? mysql_close($objConnect); ?> </body> </html>
<form name="frmSearch" method="post" action="<?=$_SERVER['PHP_SELF']?>"> //ตรงนี้ต้องเปลี่ยนไหมครับ
<html> <head> <title>ค้นหา</title> </head> <body> <form name="frmSearch" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <table width="599" border="1"> <tr> <th>ราคาห้องพัก <select name="price" id="price"> <option>- เลือกราคา -</option> <option value="1" <? if($price==1){?>selected<? }?>>น้อยกว่า1000</option> <option value="2" <? if($price==2){?>selected<? }?>>1001-1500</option> <option value="3" <? if($price==3){?>selected<? }?>>1501-2000</option> <option value="4" <? if($price==4){?>selected<? }?>>2001-2500</option> <option value="5" <? if($price==5){?>selected<? }?>>2501-3000</option> <option value="6" <? if($price==6){?>selected<? }?>>มากกว่า 3000</option> </select> ค้นหา <input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>"> <input type="submit" value="Search"></th> </tr> </table> </form> <? @include("connect.php"); ?> <? if($_REQUEST['price']!=''){ $price = $_REQUEST['price']; switch($price){ case 1: $where = " WHERE price_prd < 1000 "; break; case 2: $where = " WHERE price_prd BETWEEN 1001 AND 1500 "; break; case 3: $where = " WHERE price_prd BETWEEN 1501 AND 2000 "; break; case 4: $where = " WHERE price_prd BETWEEN 2001 AND 2500 "; break; case 5: $where = " WHERE price_prd BETWEEN 2501 AND 3000 "; break; case 6: $where = " WHERE price_prd > 3000 "; break; } } if($_REQUEST["txtKeyword"] != ""){ $detail = $_REQUEST["txtKeyword"]; $where = " WHERE (name_prd LIKE '%".$detail."%') "; } if($_REQUEST['price']!='' && $_REQUEST["txtKeyword"] != ""){ $price = $_REQUEST['price']; $detail = $_REQUEST["txtKeyword"]; switch($price){ case 1: $where = " WHERE price_prd < 1000 OR name_prd LIKE '%".$detail."%' "; break; case 2: $where = " WHERE price_prd BETWEEN 1001 AND 1500 OR name_prd LIKE '%".$detail."%'"; break; case 3: $where = " WHERE price_prd BETWEEN 1501 AND 2000 OR name_prd LIKE '%".$detail."%'"; break; case 4: $where = " WHERE price_prd BETWEEN 2001 AND 2500 OR name_prd LIKE '%".$detail."%'"; break; case 5: $where = " WHERE price_prd BETWEEN 2501 AND 3000 OR name_prd LIKE '%".$detail."%'"; break; case 6: $where = " WHERE price_prd > 3000 OR name_prd LIKE '%".$detail."%'"; break; } } else{ $where = " price_prd > 0"; } $strSQL = "SELECT * FROM ชื่อtable $where "; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); ?> <table width="600" border="1"> <tr> <th width="91"> <div align="center">id_prd </div></th> <th width="98"> <div align="center">name_prd </div></th> <th width="198"> <div align="center">ref_id_type </div></th> <th width="97"> <div align="center">detail_prd </div></th> <th width="59"> <div align="center">price_prd </div></th> <th width="71"> <div align="center">photo_prd</div></th> </tr> <? while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td><div align="center"><?=$objResult["id_prd"];?></div></td> <td><?=$objResult["name_prd"];?></td> <td><?=$objResult["ref_id_type"];?></td> <td><div align="center"><?=$objResult["detail_prd"];?></div></td> <td align="right"><?=$objResult["price_prd"];?></td> <td align="right"><?=$objResult["photo_prd"];?></td> </tr> <? } ?> </table> <? //mysql_close($objConnect); ?> </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง