|
 |
|
ขอแนวทางในการสร้าง drop down list ในการดึงข้อมูลจากฐานข้อมูลหน่อยครับ |
|
 |
|
|
 |
 |
|
test.php
Code (PHP)
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(document).ready(function(){
function test3(){
$("select#two").change(function(){
var url="1.php";
var dataSet={name:'gogo','two':$("select#two").val()}
//console.log(dataSet)
$.post(url,dataSet,function(data){
$("span#show").html(data);
});
});}
function x1(){
$.ajax({
url:"1.php",
success:function(data){
$("#two").html(data); //Get data
}
});
}
x1();
test3();
});
</script>
</head>
<body>
<select id="two" name="two">
</select>
<br/>
<span id="show">
<select id="">
<option value="one">test select</option>
</select>
</body>
</html>
1.php
Code (PHP)
<?php
$test = $_POST['two'];
$conn = mysql_connect("localhost","root","1234");
mysql_select_db("make",$conn);
if($_POST['name']==''){
$sql="SELECT * FROM makes ";
$result=mysql_query($sql);
echo "<option>select";
echo"</option>";
while($res=mysql_fetch_array($result))
{
echo"<option value='".$res['m_id']."'>";
echo $res['m_caption'];
echo "</option>";
}
}
else if($_POST['name']=='gogo'){
$sql="SELECT * FROM types Where t_id='$test'";
$result=mysql_query($sql);
echo "<select>";
echo "<option>Test select";
echo "</option>";
while($res=mysql_fetch_array($result))
{
echo "<option value='".$res['t_id']."'>";
echo $res['t_caption'];
echo "</option>";
}
echo "</select>";
} ?>
ผมใช้ jquery ajax ครับ ยังไงลองๆ เอาไปประยุกต์สร้างเบสลองดูนะครับ เป็นแนวทางผมก็ทำแบบนี้เหมือนกัน ของผมใช้เลือกยี่ห้อรถ แล้วก็รุ่นรถ ใน thaicreate ก็มีนะครับ javascript
|
 |
 |
 |
 |
Date :
2013-06-12 01:05:47 |
By :
novicecode |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|