|
 |
|
พี่ๆค่ะ ช่วยดูโค้ดการทำเมนูหมวดหมู่สินค้าที่มีอยู่ในฐานข้อมูลมาแสดงหน่อย |
|
 |
|
|
 |
 |
|
เด็กสมัยนี้ช่างจินตนาการ.. จริ๊งๆๆๆ
Code (PHP)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> https://www.thaicreate.com/php/forum/077354.html </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div style="background-image:url('pic-1.jpg');background-repeat:no-repeat;height:330px;width:170px;border:2px solid gray;text-align:center;">
<div id="categoryDisplay" style="padding-top:3em;height:2em;"></div>
<div style="position:relative;top:40px;">
<input type="text" name="searchText" /><br /><br />
<select name="cateID" id="cateID">
<option value="1">ทั้งหมด</option>
<option value="2">เสื้อ</option>
<option value="3">กางเกง</option>
</select>
</div>
</div>
<script language="javascript">
$("#cateID").change(function(){
var showText = "";
$("#cateID option:selected").each(function(){
showText = $(this).text();
});
$("#categoryDisplay").text(showText);
});
</script>
</body>
</html>

|
 |
 |
 |
 |
Date :
2012-04-21 22:18:41 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือไม่ใช่แบบนั่นน่ะค่ะ โค้ดของนู๋เป็นโค้ด ลิส ที่ใช้ serach ที่ดึงมาจากฐานข้อมูล category

แล้วนู๋อยากให้มันออกเป็นเมนูด้วยค่ะและเมื่อคลิกก็จะโชว์สินค้าของหมวดนั่นอ่ะค่ะ ช่วยลองดูใหทีน่ะค่ะ

อยากให้มันออกมาประมานนี้อ่ะค่ะ งง รึปล่าวค่ะ ยังช่วยมาตอบเรื่อยๆน่ะค่ะ นู๋ก็เรียบเรียงคำพูดไม่ถูก อิอิ
|
 |
 |
 |
 |
Date :
2012-04-21 22:42:26 |
By :
นุ้งหนิง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

Code (PHP)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> https://www.thaicreate.com/php/forum/077354.html </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div style="background-image:url('pic-1.jpg');background-repeat:no-repeat;height:330px;width:170px;border:2px solid gray;text-align:center;">
<div id="categoryDisplay" style="padding-top:3em;height:2em;">เสื้อ<br />กางเกง</div>
<div style="position:relative;top:40px;">
<input type="text" name="searchText" id="searchText" /><br /><br />
<select name="cateID" id="cateID">
<option value="1">ทั้งหมด</option>
<option value="2">เสื้อ</option>
<option value="3">กางเกง</option>
</select>
<br /><br />
<input type="button" value="ค้นหา" id="submitSearch" style="width:100px;padding:2px;"/>
</div>
</div>
<div style="position:absolute;top:8px;left:190px;border:2px solid gray;width:750px;height:380px;overflow:auto;" id="getProduct">
</div>
<script language="javascript">
$("#cateID").change(function(){
var showText = "";
$("#cateID option:selected").each(function(){
showText = $(this).text();
});
//$("#categoryDisplay").empty().append(showText);
$("#categoryDisplay").text(showText);
});
$("#submitSearch").click(function(){
var searchString = $("#searchText").val(),
catid = $("#cateID option:selected").val(),
catString = $("#cateID option:selected").text();
$.post("searchProduct.php",{searchProduct:searchString,categoryID:catid,categoryText:catString},function(output){
$("#getProduct").empty().append(output);
});
});
</script>
</body>
</html>
ไฟล์ searchProduct.php
Code (PHP)
<?php
/*
$no=1;
$sql = "select * from product where productName like '%{$_POST["searchProduct"]}%' ";
$result = mysql_query($sql) or die(mysql_error()."::".$sql);
while($data = mysql_fetch_assoc($result)){
echo "$no.)".$data["productID"]."/".$data["productName"]."/".$data["price"]."<br />\n";
}
*/
echo $_POST["searchProduct"];
echo "<br />";
echo $_POST["categoryID"];
echo "<br />";
echo $_POST["categoryText"];
?>
|
 |
 |
 |
 |
Date :
2012-04-22 10:08:18 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ sakuraei คือบรรทัดที่
19.<option value="1">ทั้งหมด</option>
20.<option value="2">เสื้อ</option>
21.<option value="3">กางเกง</option>
คือดึงมาจากฐานข้อมูลอ่ะค่ะม่ะใช่ใส่เองยังไงลองดูโค้ดของนู๋และแก้ให้หน่อยน่ะค่ะ
index.php
<?
$sql = "SELECT * FROM category"
. " ORDER BY catry_name";
$result2 = mysql_query($sql) or die(mysql_error());
?>/*ล่างhead*/
/*อยากให้เป็นเมนูตรงนี้*/
<a><form method="post" align="left" action="index.php">
<table width="95%" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="">
<tr><td><center><input type="text" name="keyword" value="<?=$keyword?>" /></center></td></tr>
<tr><td><span class="emailcolor">หมวดสินค้า :</span><select name="catry_id">
<option value="-1">ทั้งหมด</option>
<? while ($row2 = mysql_fetch_array($result2)) {
if ($row2["cat_id"] == $cat_id) {
?>
<option value="<?=$row2["catry_id"]?>" selected="selected"><?=$row2["catry_name"]?></option>
<? } else { ?>
<option value="<?=$row2["catry_id"]?>"><?=$row2["catry_name"]?></option> /*คือ3บรรทัดบนนี้เป็นlistboxตอนกดค้นหาก็ออกมาตามหมวดหมู่่น่ะค่ะ แต่นู๋อยากเอาส่วนนี้ไปปรับปรุงให้เป็น ลิสเมนูค่ะ ถ้าค้นหาจะต้องกด submit ใช่ไหมค่ะ แต่นีคลิกที่ตัวอักษรก็จะโชว์มาค่ะ*/
<? }
}
?>
</select></td></tr>
<tr><td><center><input type="image" value="submit" src="smkdj_template/image/search"/></center></td></tr></table>
</form>
</a></div>
รบกวนหน่อยน๊าค๊า
|
 |
 |
 |
 |
Date :
2012-04-22 14:58:15 |
By :
นุ้งหนิง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณก็ select แล้ว while มันเอาสิครับ
|
 |
 |
 |
 |
Date :
2012-04-22 15:06:25 |
By :
บังเอิญผ่านมาเห็น |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่อได้ละค่ะขอบคุณทุกคนน่ะค่ะ
ใช้ชุดนี้อะ
Code (PHP)
include "type_list.php";
type_list.php
<?
$sql="select * from category"
. " ORDER BY catry_name";
$result3=mysql_db_query($dbname,$sql);
echo "<ul>";
while($result3=mysql_fetch_array($result2)) {
$catry_id=$result3[catry_id];
$catry_name=$result3[catry_name];
echo "<a href='index.php?catry_id=$catry_id' >$catry_name</a>
<br><br>";
}
echo "</ul>";
?>
|
 |
 |
 |
 |
Date :
2012-04-22 15:13:57 |
By :
นุ้งหนิง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|