首先,我很熟悉編寫函數和php的知識,所以請耐心等待,並感謝您的意見和幫助。函數變量和php的問題(使用MySQL的下拉菜單)
我從MySQL數據庫中有三個動態加載的下拉菜單。前兩個傳遞一個變量,工作很好。 第三次下拉需要傳遞兩個值,我無法使其工作。
PHP:
<select name="COURSE" onChange="get_Results(this.value)">
<option>Select Course</option>
<?php
require "config.php";
$CURR=$_GET['CURR'];
$COURSE=$_GET['COURSE'];
$query = "SELECT DISTINCT CURR, COURSE FROM UGASU11 WHERE CURR = '$CURR' order by COURSE";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)) { ?>
<option value=<?php echo $row['CURR'].",".$row['COURSE']?>><?php echo $row['COURSE']?></option>
<? } ?>
</select>
其中,當用戶從第二下拉輸出選擇ADPR:
<select name="COURSE" onChange="get_Results(this.value)">
<option>Select Course</option>
<option value=ADPR,3110>3110</option>
<option value=ADPR,3520>3520</option>
<option value=ADPR,5910>5910</option>
<option value=ADPR,5990 H>5990 H</option>
</select>
get_Results功能:
function get_Results(CURR,COURSE) {
var strURL="/textbookresults.php?CURR="+CURR+"&COURSE="+COURSE;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
document.getElementById('RESULTS_div').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
MySQL查詢在textbookresults.php :
$query = "SELECT * FROM UGASU11 WHERE CURR = '$CURR' AND COURSE = '$COURSE'";
我不確定問題出在哪裏。任何幫助深表感謝。我現在一直拉着我的頭髮兩天。
謝謝!
編輯: 下面是完整的textbooks.php:
<?
// www.plus2net.com //
require "config.php";
$TERM=$_GET['TERM'];
$CURR=$_GET['CURR'];
$COURSE=$_GET['COURSE'];
$PRODUCT_NAME=$_GET['PRODUCT_NAME'];
$AUTHOR=$_GET['AUTHOR'];
$PUBLISHER=$_GET['PUBLISHER'];
$INSTRUCTOR=$_GET['INSTRUCTOR'];
$PRODUCT_THUMBNAIL=$_GET['PRODUCT_THUMBNAIL'];
$PRODUCT_CODE=$_GET['PRODUCT_CODE'];
$query = "SELECT * FROM UGASU11 WHERE CURR = '$CURR' AND COURSE = '$COURSE' order by INSTRUCTOR";
$qry_result = mysql_query($query) or die(mysql_error());
$display_string = "<table style='color:#fff;'>";
while($row = mysql_fetch_array($qry_result)){
$display_string .= "<tr>";
$display_string .= "<td colspan=3><b>Instructor: $row[INSTRUCTOR] ($row[CURR] $row[COURSE])</b></td>";
$display_string .= "</tr>";
$display_string .= "<tr>";
$display_string .= "<td> </td>";
$display_string .= "</tr>";
$display_string .= "<tr>";
$display_string .= "<td colspan=2 rowspan=4><img src=\"/Merchant5/$row[PRODUCT_THUMBNAIL]\" /></td>";
$display_string .= "<td><a href=\"/product/$row[PRODUCT_CODE].html\" onclick=\"return GB_showCenter('Product', this.href, 500, 500, callback_fn)\">$row[PRODUCT_NAME]</a></td>";
$display_string .= "</tr>";
$display_string .= "<tr>";
$display_string .= "<td>Author: $row[AUTHOR]</td>";
$display_string .= "</tr>";
$display_string .= "<tr>";
$display_string .= "<td>Publisher: $row[PUBLISHER] <br /> </td>";
$display_string .= "</tr>";
$display_string .= "<tr>";
$display_string .= "<td style='float:right;'><a href=\"/product/$row[PRODUCT_CODE].html\" onclick=\"return GB_showCenter('Product', this.href, 500, 500, callback_fn)\"><img src=\"/Merchant5/graphics/00000001/images/AddtoBasket.png\" /></a></td>";
$display_string .= "</tr>";
$display_string .= "<tr>";
$display_string .= "<td colspan=3><br /><hr /><br /></td>";
$display_string .= "</tr>";
}
$display_string .= "</table>";
echo $display_string;
?>
,這裏是我目前得到響應:
<table style='color:#fff;'></table>
請指出問題**就是**:錯誤信息?空白值?意外的價值?謝謝,歡迎。 – 2011-06-03 15:43:10
一個問題是,在將它們添加到您的SQL語句之前,您並沒有轉義$ _GET參數。 – 2011-06-03 15:43:12
您是否需要您的用戶才能選擇比課程更多的課程? – SamT 2011-06-03 15:45:40