|
 |
|
ช่วยด้วยครับ ต้องแก้โค้ดตรงไหนถึง ใส่ ราคา หรือใส่คำที่ค้นอย่างเดียวก็ค้นหาได้ |
|
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2011-05-07 09:28:33 |
By :
buraratn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ไม่เป็นเลยหรอคับ
แล้วมัน error query ก็เพราะไม่มี ไฟล์ connect.php
Code (PHP)
<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'];
$name_prd = $_REQUEST["txtKeyword"];
switch($price){
case 1:
$where = " WHERE price_prd < 1000 OR name_prd LIKE '%".$name_prd."%' ";
break;
case 2:
$where = " WHERE price_prd BETWEEN 1001 AND 1500 OR name_prd LIKE '%".$name_prd."%'";
break;
case 3:
$where = " WHERE price_prd BETWEEN 1501 AND 2000 OR name_prd LIKE '%".$name_prd."%'";
break;
case 4:
$where = " WHERE price_prd BETWEEN 2001 AND 2500 OR name_prd LIKE '%".$name_prd."%'";
break;
case 5:
$where = " WHERE price_prd BETWEEN 2501 AND 3000 OR name_prd LIKE '%".$name_prd."%'";
break;
case 6:
$where = " WHERE price_prd > 3000 OR name_prd LIKE '%".$name_prd."%'";
break;
}
}
$strSQL = "SELECT * FROM tb_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>
connect.php
<?
# Database - Start
$db_HostName = "localhost";
$db_Name = "ใส่ชื่อตรงนี่นะคับ"; // database name
$db_UserName = "ใส่ชื่อตรงนี่นะคับ"; // username
$db_Password = "ใส่ชื่อตรงนี่นะคับ"; // password
$link = mysql_connect($db_HostName , $db_UserName , $db_Password) or die ("Cannot connect to database '$db_Name' : ".mysql_error());
mysql_select_db ($db_Name);
mysql_query("SET NAMES TIS620");
# Database - End
?>
|
 |
 |
 |
 |
Date :
2011-05-07 10:22:59 |
By :
TEST |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากเลยครับ คือผมเพิ่งหัดเขียนนะครับ คงต้องขอคำแนะนำเยอะๆหน่อยนะครับ
อันนี้เป็นไฟล์ connect.php อันเดิมครับ แล้วทำไหมมันถึง error query ละครับCode (PHP)
<?
$host="localhost";
$user="root";
$pw="1234";
$dbname="db_shop";
$c = mysql_connect($host,$user,$pw);
$objDB = mysql_select_db("db_shop");
mysql_query("SET character_set_results=tis620");
mysql_query("SET character_set_client=tis620");
mysql_query("SET character_set_connection=tis620");
if (!$c)
{
echo "<H3>ไม่สามารถติดต่อฐานข้อมูลได้</H3>";
exit();
}
?>
และอีกอันนี้ครับที่ยังไม่ทราบ โค้ดบันทัดนี้แปลว่าไรหรอครับ โดยเฉพาะ action="<?=$_SERVER['PHP_SELF']?> ใส่เพื่ออะไรครับ php_self คืออะไรครับ
Code (PHP)
<form name="frmSearch" method="post" action="<?=$_SERVER['PHP_SELF']?>">
|
 |
 |
 |
 |
Date :
2011-05-07 11:00:26 |
By :
buraratn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูดความรู้
|
 |
 |
 |
 |
Date :
2011-05-07 11:04:46 |
By :
suchinee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนผู้รู้มาตอบทีครับ
|
 |
 |
 |
 |
Date :
2011-05-07 11:44:02 |
By :
buraratn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ สำหรับคำแนะนำครับ
|
 |
 |
 |
 |
Date :
2011-05-07 13:04:36 |
By :
buraratn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณที่ให้กำลังใจครับ จะพยายามและอ่านมากกว่านี้ครับ
|
 |
 |
 |
 |
Date :
2011-05-07 21:01:55 |
By :
buraratn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|