|
 |
|
รบกวนด้วยครับ นำโค้ดแบ่งหน้าของคุณ PlaKriMมาลองใช้ ได้ผลแบบนี้ครับ ไม่ทราบว่าผิดตรงไหนหรอครับ |
|
 |
|
|
 |
 |
|
https://www.thaicreate.com/php/forum/025968.htmlCode (PHP)
<html>
<head>
<title>ค้นหา</title>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("jquery", "1.3.2");
</script>
<script type="text/javascript">
function get_search (p, t){
var p = $("#price").val();
var t = $("#txtKeyword").val();
if(p.length==0 && t.length==0){
alert('โปรดเลือกราคาหรือชื่อหอพักที่ต้องการค้นหา');
}
}
</script>
</head>
<body>
<form name="frmSearch" method="post" action="<?=$_SERVER['PHP_SELF']?>" onSubmit="get_search (price, txtKeyword)">
<table width="641" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="631">ราคาห้องพัก
<select name="price" id="price">
<option value="">- เลือกราคา -</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");
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 2;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE id_prd = '" . $_GET["id"] . "'";
}
$sql = "SELECT * FROM tb_product" . $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $connection_id);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $connection_id));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
echo $rows["product_name"]."<br>";
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, $send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
<?
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;
}
}
?>
<table border="0" cellpadding="0" cellspacing="1">
<tr>
<th width="92"> <div align="center">รหัสหอพัก</div></th>
<th width="97"> <div align="center">ชื่อหอพัก </div></th>
<th width="140"> <div align="center">ประเภทหอพัก </div></th>
<th width="83"> <div align="center">ราคา</div></th>
<th width="110"> <div align="center">รูปภาพ </div></th>
<th width="170"> <div align="center">รายละเอียด</div></th>
</tr>
<?
if($price!='' || $txtKeyword!=''){
$strSQL = "SELECT * FROM tb_product ";
$strSQL .= " LEFT JOIN tb_type ON tb_product .ref_id_type = tb_type.id_type";
$strSQL .= " $where";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td height="50"><div align="center"><?=$objResult["id_prd"];?></div></td>
<td><div align="center"><?=$objResult["name_prd"];?></div></td>
<td><div align="center"><?=$objResult["name_type"];?></div></td>
<td><div align="center"><?=$objResult["price_prd"];?></div></td>
<td align="right"><div align="center"><img src="photo/<?=$objResult["photo_prd"];?>" width="30" /></div>
</td> <td>[ <A HREF='search_view.php?id_prd=<?=$objResult["id_prd"];?>'>แสดงรายละเอียด </A>] </div></td>
</tr>
<? }}?>
</table>
<?
//mysql_close($objConnect);
?>
</body>
</html>

Tag : PHP, MySQL

|
ประวัติการแก้ไข 2011-05-13 14:07:22 2011-05-13 14:33:27 2011-05-13 14:34:10
|
 |
 |
 |
 |
Date :
2011-05-13 13:59:16 |
By :
buraratn |
View :
865 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บรรทักที่ 53 ตัวแปร $connection_id รับค่ามาจากตัวไหนครับ มันผิดที่ตรงนี้หรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2011-05-13 14:10:20 |
By :
grandraftz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<? @include("connect.php");
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 2;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE id_prd = '" . $_GET["id"] . "'";
}
$sql = "SELECT * FROM tb_product" . $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
echo $rows["name_prd"]."<br>";//ข้อมูที่ต้องการแสดงอยู่ด้านล่างแล้วครับ ต้องทำยังไงกับบรรทัดนี้
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, $send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>

|
 |
 |
 |
 |
Date :
2011-05-13 14:32:26 |
By :
buraratn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
path file ที่ include ถูกหรือเปล่าครับ
แล้วลองเช็ค error จากการ query หรือยัง
ลองเอา or die(mysql_error()); ไปต่อท้ายตอนที่query ดูครับ อาจจะ เส้นผมบังภูเขา ก็ได้
|
 |
 |
 |
 |
Date :
2011-05-13 17:13:57 |
By :
aprodise |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งง ครับ เพิ่งหัดเขียนครับเลยเข้าใจยากหน่อย
|
 |
 |
 |
 |
Date :
2011-05-13 17:23:36 |
By :
buraratn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
copy function มาด้วยซิครับ 
|
 |
 |
 |
 |
Date :
2011-05-14 00:35:09 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|