码迷,mamicode.com
首页 > Web开发 > 详细

Ajax+juqery+php 之两个select option控件传值

时间:2016-10-22 00:57:28      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:php+ajax+jquery

<?php

for($i=0;$i<$num;$i++)

{  

    $n=$i+1;


  echo "<tr><td align=center id=th2>$n";


   $idd=‘stt_‘.$i ;

   echo "<input type=text name=kname[$i] value=‘$kname[$i]‘  placeholder=‘单位检索‘ class=‘stt‘ id=\"$idd\" ></input>";

   $add=‘add_‘.$i ;

  echo "<td><center><input type=text name=acc_name1[$i] value=‘$acc_name1[$i]‘ size=30></td>

<td><center><input type=text name=amt1[$i] value=‘$amt1[$i]‘ class=‘add‘ id=\"$add\" size=10></td>";

  

    $id1=‘user_‘."$i";

    echo "<td ><select name=user[$i] id=\"$id1\">

           

              </select>";

 echo"</tr>";

 }


echo "</table>";


?>



<script type="text/javascript">

$(".sty").change(function() {

    

        var inno = this.value;

var next = this.id.split(‘_‘)[1]; 

        $.ajax({

            type:‘post‘,

            url:"find_user.php?"+ Math.round(Math.random()*100),

            data:{"inno":inno},

contentType: "application/x-www-form-urlencoded; charset=utf-8", 

            success:function(data) { 

  data = eval(‘(‘+data+‘)‘);

   $("#user_"+next).empty();

  for(i=0;i<data.length;i++){

$("<option></option>").val(data[i].empl).text(data[i].empl+‘-‘+data[i].name+‘-‘+data[i].dep).appendTo($("#user_"+next));

}

            },

            error:function() { alert("error"); }

            });  

 

       

    });

</script>



//find_user.php


<?php

require_once(‘/php/public/id.inc‘);

require_once(‘/php/public/opendb.inc‘);

require("/php/public/power.inc");

header("Content-type: text/html;charset=utf-8");


    function field_ora($sql) {

 global $dbhUTF;

 $stmt = $dbhUTF->prepare("$sql");

 if ($stmt->execute()) {

  return  $stmt->fetch();

 }

    }


$inno=$_POST[inno];


          $sql_exx="select depart_no from acc_gl_depart where acc_depart_no=‘$inno‘";

          $sql_exp=$dbhUTF->prepare($sql_exx);

 $sql_exp->execute();

 list($dept_clear)=$sql_exp->fetch();

 

 

 if($dept_clear==‘516000‘){

 

   $sql4="select employee_no,name,get_depart(employee_no)

from employee

where depart_no =‘$dept_clear‘ and lead_code=‘20‘ ";

 $sql4_exe=$dbhUTF->prepare($sql4);

 $sql4_exe->execute();

 $i=0;

 while (list($employee_no,$name,$dept_no)=$sql4_exe->fetch()){

#echo "$employee_no-$name-$dept_no";

 $a[$i]=array(‘empl‘=>$employee_no,‘name‘=>$name,‘dep‘=>$dept_no);

 $i++;

}

    }

 elseif($dept_clear==‘300001‘ or $dept_clear==‘300002‘ or $dept_clear==‘300003‘ or $dept_clear==‘300004‘){

 

  $dep_no3=substr($dept_clear,0,2);


 $sql4="select employee_no,name(employee_no),get_depart(employee_no)

from psm_double_work

where depart_no like ‘$dep_no3%‘";

 $sql4_exe=$dbhUTF->prepare($sql4);

 $sql4_exe->execute();

 $i=0;

 while (list($employee_no,$name,$dept_no)=$sql4_exe->fetch()) {

#echo "$employee_no-$name-$dept_no";

 $a[$i]=array(‘empl‘=>$employee_no,‘name‘=>$name,‘dep‘=>$dept_no);

 $i++;

}

 }

 ELSE if($dept_clear==‘J11040‘){

 

   $sql4="select employee_no,name,get_depart(employee_no)

from employee

where depart_no =‘$dept_clear‘ and lead_code=‘50‘";

 $sql4_exe=$dbhUTF->prepare($sql4);

 $sql4_exe->execute();

 $i=0;

 while (list($employee_no,$name,$dept_no)=$sql4_exe->fetch()){

#echo "$employee_no-$name-$dept_no";

 $a[$i]=array(‘empl‘=>$employee_no,‘name‘=>$name,‘dep‘=>$dept_no);

 $i++;

}

    }

 else{

  $dep_no1=substr($dept_clear,0,5)."0";

  list($sqlcnt)=field_ora("select count(*) from psm_double_work where depart_no=‘$dep_no1‘");

   if ($sqlcnt>0)

   {

 $sql4="select employee_no,name(employee_no),get_depart(employee_no)

from psm_double_work

where depart_no=‘$dep_no1‘ order by lead_code desc ";

 $sql4_exe=$dbhUTF->prepare($sql4);

 $sql4_exe->execute();

 $i=0;

 while (list($employee_no,$name,$dept_no)=$sql4_exe->fetch()) {

# echo "$employee_no-$name-$dept_no";

 $a[$i]=array(‘empl‘=>$employee_no,‘name‘=>$name,‘dep‘=>$dept_no);

 $i++;

}

    }

  else

    {

$dep_no2=substr($dept_clear,0,3)."000";

list($sqlcnt2)=field_ora("select count(*) from psm_double_work where depart_no=‘$dep_no2‘");

  if ($sqlcnt2>0)

  {

 $sql4="select employee_no,name(employee_no),get_depart(employee_no)

from psm_double_work

where depart_no=‘$dep_no2‘";

 $sql4_exe=$dbhUTF->prepare($sql4);

 $sql4_exe->execute();

 $i=0;

 while (list($employee_no,$name,$dept_no)=$sql4_exe->fetch()) {

     #echo "$employee_no-$name-$dept_no";

  $a[$i]=array(‘empl‘=>$employee_no,‘name‘=>$name,‘dep‘=>$dept_no);

 $i++;

   }

}

  else

{

 $dep_no3=substr($dept_clear,0,2)."0000";


 $sql4="select employee_no,name(employee_no),get_depart(employee_no)

from psm_double_work

where depart_no=‘$dep_no3‘";

 $sql4_exe=$dbhUTF->prepare($sql4);

 $sql4_exe->execute();

 $i=0;

 while (list($employee_no,$name,$dept_no)=$sql4_exe->fetch()) {

# echo "$employee_no-$name-$dept_no";

 $a[$i]=array(‘empl‘=>$employee_no,‘name‘=>$name,‘dep‘=>$dept_no);

 $i++;

}

  list($employee_no,$name,$dept_no)=$sql4_exe->fetch();

  if (!$employee_no) {


  $sql5="select employee_no,name(employee_no),get_depart(employee_no)

 from employee

where depart_no=‘$dept_clear‘";

  $sql5_exe=$dbhUTF->prepare($sql5);

  $sql5_exe->execute();

                  $i=0;

 while (list($employee_no,$name,$dept_no)=$sql5_exe->fetch()) {

 #echo "$employee_no-$name-$dept_no";

  $a[$i]=array(‘empl‘=>$employee_no,‘name‘=>$name,‘dep‘=>$dept_no);

  $i++;

}


   }

}


    }


  }

 

   echo json_encode($a);

?>

Ajax+juqery+php 之两个select option控件传值

标签:php+ajax+jquery

原文地址:http://12200048.blog.51cto.com/12190048/1864405

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!