dongyupen6269 2018-06-14 12:27
浏览 56
已采纳

PHP foreach echo将“符号”打印为值

I fetched data dynamically from from MySQL using a drop down menu through Ajax which was successful but when I echo the array values, instead of giving me the list of emails it was showing just symbols.

Take a look at the image below: enter image description here

From the Email List, those are the symbols that were echo out.

here is my php code

if(isset($_POST["confirm_no"])){

    $d = $_POST['confirm_no'];
    $query = mysqli_query($mysqli, "select * from jobseeker WHERE confirm_no LIKE  '$d%'");

    //Display  list
    if(mysqli_num_rows($query) > 0){
          $row = mysqli_fetch_array($query);
            foreach ($row as $r) {
            $emailArr[] = $r["mails"];
        }
         $emails = implode(";", $emailArr);

        echo $emails;

    }else{
        echo 'No email for this selection.';
    }
}

And the jQuery

$(document).ready(function(){ 

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

});
});
});

Why is it echoing out this symbols?

  • 写回答

2条回答 默认 最新

  • dongyang2229 2018-06-14 12:33
    关注

    Rebuild your code as:

    //Display  list
    if(mysqli_num_rows($query) > 0){
        // You have many results - fetch them all iteratively
        // use `fetch_assoc` to have ability to use `mails`
        while ($row = mysqli_fetch_assoc($query)) {
            $emailArr[] = $row["mails"];
        }
        $emails = implode(";", $emailArr);
    
        echo $emails;
    }else{
        echo 'No email for this selection.';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求