dongpi9494 2011-06-03 15:40
浏览 38
已采纳

函数变量和php的问题(使用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.

I have three dynamically loaded drop downs from a MySQL database. 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:

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

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

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:
" + req.statusText);
       }
    }            
     }        
req.open("GET", strURL, true); 
req.send(null);
   }
}

MySQL Query in textbookresults.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:

        <?
        // 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> 
  • 写回答

1条回答 默认 最新

  • duancuan7057 2011-06-03 15:44
    关注
    <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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题