0

在我在php中工作时的下面代码中,下拉列表在选择考试名称时工作良好,当我选择相应的subject_code时,来了。值,当我单击上传时,它会显示 course_code 值而不是填充 subject_coide,当我单击上传时,它会填充 subject_code。所以任何人都请帮助我。

            Upload1_site (controller)
                   <?php

              class Upload1_site extends ci_controller
                 {
                  function index()
            {   
                $this->load->view('new_view');


            } 
           function upload()
            {   
                $this->load->view('new1_view');


            } 


             }//end of class         ?>




              new_view (View 1)

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript">
         $(document).ready(function(){
     $(".hai").change(function()
     {
     var id=$(this).val();
     // Please find the course_code, course_code was not found
      var dataString = 'course_code='+ id;
        $.ajax
        ({
            type: "POST",
            url: "upload1_site/upload",
            data: dataString,
            cache: false,
            success: function(html)
            {
                $(".hai2").html(html);
            } 
        });

    });

    $(".hai2").change(function()
    {
        var id2=$("#hai2").val();
        alert(id2);
        var dataString = 'subject_code='+ id2;
        $.ajax
        ({
            type: "POST",
            url: "upload1_site/upload",
            data: dataString,
            cache: false,
            success: function(html)
            {
                $(".hai3").html(html);
            }
        });

    });
           });
         </script>
         </head>



     <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

         File to import: 
      <input size='30' type='file' name='filename'>
         <br>
      Select Exam name:
     <select name="hai" class="hai" id="hai">

          <?php
          mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());

            mysql_select_db("slseatapp") or die(mysql_error());

          $query="select  distinct exam_name from examcourse";
          $result = mysql_query($query);
           while($nt=mysql_fetch_array($result)) {
           echo "<option value='".$nt['exam_name']."'>".$nt['exam_name']."</option>";
            }

            ?>
           </select>
               <br> 

           <span class="hai2">
    Course code:
    <select name="hai2" id="hai2">
    <?php if($_REQUEST['hai']){?>

    <option>Select</option> 
     <?php

        $query="SELECT distinct course_code FROM examcourse where exam_name =  '".$_REQUEST['hai']."' ";
        $result = mysql_query($query);
        while($nt=mysql_fetch_array($result)) {
        echo "<option value='".$nt['course_code']."'>".$nt['course_code']."</option>";
        }
    ?>
     <?php }else{?>
    <option>Select</option>
     <?php }?>
       </select>
         </span>
         <br>
          <span class="hai3">
    Subject code:
    <select name="hai3" id="hai3">
    <?php if($_REQUEST['hai2']){?>

    <option>Select</option>
     <?php

        $query="SELECT distinct subject_code FROM coursesubject where course_code = '".$_REQUEST['hai2']."'";
        $result = mysql_query($query);
        while($nt=mysql_fetch_array($result)) {
        echo "<option value='".$nt['subject_code']."'>".$nt['subject_code']."</option>";
        }
    ?>
      <?php }else{?>
    <option>Select</option>
        <?php }?>
            </select>
           </span>
                <br>
          <input type="submit" name="submit" value="Upload"></form>



         <?php 

         mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());

           mysql_select_db("slseatapp") or die(mysql_error());

              //Upload File 
           if (isset($_POST['submit'])) { 
           if (is_uploaded_file($_FILES['filename']['tmp_name'])) { 

         //Import uploaded file to Database 
           $row = 1; 
            $handle = fopen($_FILES['filename']['tmp_name'], "r"); 
              $var = $_POST['hai'];
               $var2 = $_POST['hai2'];
              $var3 = $_POST['hai3'];

           //$res=mysql_fetch_array(mysql_query("SELECT subject_code FROM coursesubject where course_code = '".$var1."'"));

         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { 

             //Update Database Values 

            $import="insert into student_table (id,register_number,name,course_code,subject_code,exam_name) VALUES('".mysql_real_escape_string($data[0])."', '".mysql_real_escape_string($data[1])."','".mysql_real_escape_string($data[2])."','$var2','".$var3."','$var')"; 
          //$import="replace into  student_table (id,register_number,name,course_code,subject_code,exam_name) VALUES('".mysql_real_escape_string($data[0])."', '".mysql_real_escape_string($data[1])."','".mysql_real_escape_string($data[2])."','$var','$var1','$var2')";


               mysql_query($import) or die(mysql_error()); 
            }
       fclose($handle);
        echo"<script>alert('Uploaded Successfully');</script>";  
           }else{
      echo"<script>alert('Failed');</script>"; 
         }


        } 
        ?>


               new2_view (view 2)

          <script language="javascript">
            function changeSelection(value){

           var length = document.getElementById("hai3").options.length;

               if(value == 0){
            for(var i = 1;i<length;i++)
              document.getElementById("hai3").options[i].selected = "selected";

             document.getElementById("hai3").options[0].selected = "";
               }

                   }
                 </script>

               <?php
               mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
               mysql_select_db("slseatapp") or die(mysql_error());

             if($_POST['course_code']){
                @$exam_name=$_POST['course_code'];
                ?>

                Course code: <select name="hai2" id="hai2">
                <option >Select</option>
                 <?php

                      $query="SELECT distinct course_code FROM examcourse where exam_name = '$exam_name' ";

                    $result = mysql_query($query);
                 while($nt=mysql_fetch_array($result)) {
            echo "<option value='".$nt['course_code']."'>".$nt['course_code']."</option>";
               }
                 ?>

              </select>
             <?php }
                if($_POST['subject_code']){
                 @$subject_code=$_POST['subject_code'];
                 ?>
                Subject code:
               <select name="hai3" multiple onChange="changeSelection(this.value)" id="hai3">
      <option value="0">Select</option>
     <?php

        $query="SELECT subject_code FROM coursesubject where course_code = '".$subject_code."'";
        $result = mysql_query($query);
        while($nt=mysql_fetch_array($result)) {
        echo "<option value='".$nt['subject_code']."'>".$nt['subject_code']."</option>";
        }
             ?>
                  </select>

                   <?php }?>
4

1 回答 1

1

试试这个

放这个

var base_url="<?=base_url()?>"

脚本标签内的某处可能在之前

$(document).ready(function(){

线

并更改线路

url: "upload1_site/upload",

url: base_url+"upload1_site/upload",

请让我知道它是否有效。

于 2013-08-08T10:58:40.130 回答