dongyong6045 2018-06-14 02:01
浏览 59

如何从MySQL获取数据作为数组并根据PHP中的下拉选择动态填充文本字段

I have two categories of Job Applicants in my database: graduates and artisans. I am trying to fetch their emails separately base on the category being selected from the drop down menu.

My objective is to fetch all the emails as an array and populate them into a text field.

for clarity, here is my HTML code:

<div class="form-group">
<div class="form-line">
<select class="form-control smode" name="smode" id="smode" >
<option value="">select Job Seekers</option>
<option value="G">Graduates Only</option>
<option value="A">Artisans Only</option>
</select>
</div>
</div>

<div class="form-group">
<label>Email List</label>
<div class="form-item">
<input type="text" name="email_list" class="form-control" /><!--Field to populate--!>
</div>                                 
</div> 

Js

$('#smode').change(function(){
var packages = $(this).val();
$.ajax({
   type:'POST',
   data:{packages:packages},
   url:'get_email.php',
   success:function(data){
       $('#email_list').val(data);
   } 

});

get_email.php

if (isset($_POST['packages'])) {
    $g =  $_POST['packages'];
    $qry = "select * from jobseeker WHERE confirm_no LIKE '$g'";
    $rec = mysqli_query($mysqli, $qry);
    if (mysqli_num_rows($rec) > 0) {

        $res = mysqli_fetch_array($rec);

        foreach ($res as $rs) {
            $emailArr[] = stripslashes(($rs["mails"]));
        }

        $emails = implode(";", $emailArr);

        echo $emails;

    }
}

Can someone please point me to the right direction.

  • 写回答

1条回答 默认 最新

  • dsmvovm27249 2018-06-14 04:44
    关注

    I'm not a JQuery guru, but I know that Javascript doesn't care for single quotes. Is JQuery similar? (Sorry, I can't add comments yet)

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题