开发者

dynamic list/menu passing variable php

开发者 https://www.devze.com 2023-03-13 03:20 出处:网络
i have this 2 list menu inside a php code ..my question is how do i get the selected value in the listmenu and pass it on a new query so that the in 2nd listmenu.. the values to be executed are select

i have this 2 list menu inside a php code ..my question is how do i get the selected value in the listmenu and pass it on a new query so that the in 2nd listmenu.. the values to be executed are selected based on the value in the 1st listmenu... Below is my code

I have 3 files named addpage.php,addpage.html and for the changing process grades.php

The addpage.php and addpage.html

<?开发者_如何转开发php

 $level =$template->form_listmenu($lnames,$lvalues,$level,"level",NULL,'width:300px;','onChange="dochange(\'gradedrop\', this.value, \'\',\'\');"',True);

$gnames=array("-- Please Select --");
$gvalues=array("");

$subnames=array("-- Please Select --");
$subvalues=array("");

$booknames=array("Select Books");
$bookvalues=array("");

$grade = $template->form_listmenu($gnames,$gvalues,$grade,"grade",NULL,'width:300px;','',FALSE);
$subject = $template->form_listmenu($subnames,$subvalues,$subject,"subject",NULL,'width:300px;','',FALSE);
$books = $template->form_listmenu($booknames,$bookvalues,$books,"books",NULL,'width:300px;','',FALSE);
 ?>

The addpage.html

<html>

 <script language=Javascript>
  function Inint_AJAX() {
   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;
  };

  function dochange(src, val, currval , currval1) {
   var req = Inint_AJAX();
   req.onreadystatechange = function () { 
      if (req.readyState==4) {
           if (req.status==200) {
                document.getElementById(src).innerHTML=req.responseText; //retuen value
           } 
       }
  };
   req.open("GET", "{domain}admin/modules/onlinetools/grades.php?data="+src+"&val="+val+"&currval="+currval+"&currval1="+currval1); //make connection
 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
 req.send(null); //send value
}

The Grades.php

<?php
    ///this is the grades.php

    $val = $_GET["val"];
$grade = $_GET["currval"];
$subject = $_GET["currval1"];

 // Generate book subject table
$sql="SELECT * FROM booksubject WHERE status = '1' AND lid = '".$val.
     "' AND subject <> '#N/A' ORDER BY subject ASC";
$query=mysql_query($sql);
$data_num=mysql_num_rows($query);
//$data=mysql_fetch_array($query);
$subnames="-- Please Select --<:>";
$subvalues="<:>";
for($i=1; $i<=$data_num; $i++){
    $data=mysql_fetch_array($query);
    $subnames.=$subcoma.$data["subject"];
    $subvalues.=$subcoma.$data["sid"];
    $subcoma="<:>"; 

}
//  Generate book  table
$bsql="SELECT * FROM books WHERE subject = '".
          $data["sid"]."' ORDER BY title ASC";
$bquery=mysql_query($bsql);
$bdata_num=mysql_num_rows($bquery);
for($b=1; $b<=$bdata_num; $b++){
    $bdata=mysql_fetch_array($bquery);
    $booknames.=$bookcoma.$bdata["title"].' - '.$bdata["book_code"];
    $bookvalues.=$bookcoma.$bdata["bid"];
    $bookcoma="<:>";        
}


$subnames=explode("<:>",$subnames);
$subvalues=explode("<:>",$subvalues);
$subject = $template->form_listmenu($subnames,$subvalues,$subject,
                                    "subject",NULL,'width:300px;','',False);
echo '<p>'.$subject.'</p>';

$booknames=explode("<:>",$booknames);
$bookvalues=explode("<:>",$bookvalues);
$books = $template->form_listmenu($booknames,$bookvalues,$books,
                                    "books",NULL,'width:300px;','',FALSE);
echo '<p>'.$books.'</p>';
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号