 |
|
1. ผมใช้ javascript (dropdown)ทำเกี่ยวกับอาหาร ชนิดของอาหาร(ข้าว,ก๋วยเตี๋ยว,เครื่องดื่ม) -->ชื่ออาหาร อยากได้ตัวอย่างโค้ด(คำสั่ง)ที่รับค่าจาก javascript (รับค่าชื่ออาหารที่สั่ง) แล้วเก็บลงในฐานข้อมูลที่เราสร้างไว้อ่ะครับ ขอบคุณครับ
2.ผมทำรายการอาหารไว้นะครับ แต่อยากให้เวลาเราเลือกแล้วจะโชว์ ราคา ของอาหารนะครับ ช่วยทีนะครับ
ข้างล่าง คือ โค้ดนะครับ
<?php
$hostname_testscript = "localhost";
$database_testscript = "food";
$username_testscript = "root";
$password_testscript = "";
$testscript = mysql_pconnect($hostname_testscript, $username_testscript, $password_testscript) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_testscript, $testscript);
$query_rs1_province = "SELECT * FROM typeoffood ORDER BY code ASC";
$rs1_province = mysql_query($query_rs1_province, $testscript) or die(mysql_error());
$row_rs1_province = mysql_fetch_assoc($rs1_province);
$totalRows_rs1_province = mysql_num_rows($rs1_province);
mysql_select_db($database_testscript, $testscript);
$query_rs1_aumphor = "SELECT * FROM product";
$rs1_aumphor = mysql_query($query_rs1_aumphor, $testscript) or die(mysql_error());
$row_rs1_aumphor = mysql_fetch_assoc($rs1_aumphor);
$totalRows_rs1_aumphor = mysql_num_rows($rs1_aumphor);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=TIS-620">
<script language="javascript" type="text/javascript">
function changeDynaList( listname, source, key, orig_key, orig_val ) {
var list = eval( 'document.form1.' + listname );
// empty the list
for (i in list.options.length) {
list.options = null;
}
i = 0;
for (x in source) {
if (source[x][0] == key) {
opt = new Option();
opt.value = source[x][1];
opt.text = source[x][2];
if ((orig_key == key && orig_val == opt.value) || i == 0) {
opt.selected = true;
}
list.options[i++] = opt;
}
}
list.length = i;
}
var provinceaumphor = new Array;
<?php
do {
?>
provinceaumphor[<?php echo $row_rs1_aumphor['productid']; ?>] = new Array( '<?php echo $row_rs1_aumphor['code']; ?>','<?php echo $row_rs1_aumphor['productid']; ?>','<?php echo $row_rs1_aumphor['foodname']; ?>' );
<?php
} while ($row_rs1_aumphor = mysql_fetch_assoc($rs1_aumphor));
?>
</script>
</head>
<body>
<form name="form1" method="post" action="">
<select name="provinceid" onchange="changeDynaList( 'aumphorid', provinceaumphor, document.form1.provinceid.options[document.form1.provinceid.selectedIndex].value, 0, 0);">
<option value="0">เลือกหมวดอาหาร</option>
<?php
do {
?>
<option value="<?php echo $row_rs1_province['code']?>"><?php echo $row_rs1_province['typename']?></option>
<?php
} while ($row_rs1_province = mysql_fetch_assoc($rs1_province));
?>
</select>
<br>
<select name="aumphorid">
<option value="0">เลือกรายการอาหาร</option>
</select>
</form>
ราคา : <===== ตรงส่วนนี้อยากให้โชว์ราคา ครับ
</body>
</html>
Database Food
Table typeoffood
- typename ข้าว, ก๋วยเตี๋ยว
- code 1, 2
product
- productid pri_key auto_increment
- code จากตาราง typeoffood
- foodname ข้าว(ข้าวผัด, หมูทอด) ก๋วยเตี๋ยว(เส้นเล็ก,เส้นใหญ่)
- price ข้าว(20,20) ก๋วยเตี๋ยว(15,15) ****
ราคาอยู่ใน ฐานข้อมูล food ตาราง product ชื่อ price ครับ
อยากให้โชว์ตามรายการอาหารที่เราเลือกอะครับ
ตัวแปรต่างๆ ผมก๊อปโค้ดจากคนอื่นมาแล้วเอามาแปลงนะครับ อย่าไปสนใจ
---------- ช่วยด้วยนะครับ -----------
ป.ล. ไปโพสใน phpthailand ไม่มีคนตอบเลยอ่ะครับ คนใน thaicreate ช่วยตอบผมด้วยนะครับ
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
12 ส.ค. 2549 01:20:00 |
By :
gangho |
View :
1932 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |