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 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题