简体   繁体   English

function 变量和 php 的问题(MySQL 的下拉菜单)

[英]problem with function variables and php (drop downs with MySQL)

First, I am very novice in my knowledge of writing functions and php, so bear with me, and Thank you for your input and help.首先,我在编写函数和 php 方面的知识非常新手,所以请多多包涵,感谢您的意见和帮助。

I have three dynamically loaded drop downs from a MySQL database.我从 MySQL 数据库中获得了三个动态加载的下拉菜单。 The first two pass one variable and work great.前两个传递一个变量并且效果很好。 The third drop down needs to pass two values and I am having trouble getting it to work.第三个下拉菜单需要传递两个值,我无法让它工作。

php: 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>

which, when a user selects ADPR from the second drop down outputs:其中,当用户从第二个下拉输出中选择 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 Function:

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 Query in textbookresults.php: MySQL 在教科书中查询结果。php:

$query = "SELECT * FROM UGASU11 WHERE CURR = '$CURR' AND COURSE = '$COURSE'";

I'm not sure where the problem is.我不确定问题出在哪里。 Any help is MUCH appreciated.任何帮助深表感谢。 I have been pulling my hair out for two days now.我这两天一直在拔头发。

THANKS!谢谢!

EDIT: here is the complete textbooks.php:编辑:这是完整的教科书。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>&nbsp;</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;
            ?>

and here is the Response I am currently getting:这是我目前得到的回应:

<table style='color:#fff;'></table> 
<option value=<?php echo $row['CURR'],$row['COURSE']?>><?php echo $row['COURSE']?></option>

change it更改

<option value="<?php echo $row['CURR'].",".$row['COURSE']?>" ><?php echo $row['COURSE']?></option>

that will make a comma separated value for this option这将为该选项生成一个逗号分隔值

    function get_Results(passedValue) { 
   var args = passedValue.split(",");
   var CUR = args[0];
   var COURSE = args[1];

     var strURL="/textbookresults.php?CURR="+CURR+"&COURSE="+COURSE; 

....remaining code... hope fully that will solve the issue ....剩余代码...完全希望能解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM