Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中分割数据的同时循环数据,并将数据传递给具有不同id的ajax html';s_Php_Jquery_Ajax_Performance - Fatal编程技术网

如何在php中分割数据的同时循环数据,并将数据传递给具有不同id的ajax html';s

如何在php中分割数据的同时循环数据,并将数据传递给具有不同id的ajax html';s,php,jquery,ajax,performance,Php,Jquery,Ajax,Performance,我有一个db医生表,里面有将近100多个医生列表,下面是我的医生PHP代码dc.PHP: $conn= mysqli_connect('localhost', 'root', '', 'test'); $query = mysqli_query($conn, "select * from doctors"); while($result=mysqli_fetch_array($query)){ $dc_name = $result['name']; $dc

我有一个db医生表,里面有将近100多个医生列表,下面是我的医生PHP代码dc.PHP:

    $conn= mysqli_connect('localhost', 'root', '', 'test');
    $query = mysqli_query($conn, "select * from doctors");
    while($result=mysqli_fetch_array($query)){
    $dc_name = $result['name'];
    $dc_img = $result['image'];
    $dc_email = $result['email'];


    echo $dc_name."||".$dc_img."||".$dc_email;
    }

    I want echo all doctors another main page index which already fixed large layout with bootstrap,html,css by using ajax calling on click

    Here is my code for ajax

    $(function(){
    $(".divscrolla").on("click", function(){
    $.ajax({
     url:'db.php',
    type:'POST',
    data:{"data":$(this).val()},
    success:function(data){
    var splitted = data.split("||");
    $("#result_name").html.splitted[0];
    $("#result_img").html.splitted[1];
    $("#result_email").html.splitted[2];
    }
    });
    });
这里我想通过AJAX显示所有100条记录

但这里我只得到第一个元素,但我在数据库中有100多条记录

我如何通过简化来解决这个问题?

你试过了吗

$resultArray=$result->fetch_all(MYSQLI_ASSOC);
$jsonstring=json_encode($resultArray);
echo$jsonstring;
然后在AJAX代码中不要拆分,让json格式帮助您。通过将数据类型设置为json
dataType:“json”,

你试过了吗

$resultArray=$result->fetch_all(MYSQLI_ASSOC);
$jsonstring=json_encode($resultArray);
echo$jsonstring;
然后在AJAX代码中不要拆分,让json格式帮助您。通过将数据类型设置为json
dataType:“json”,

$(function(){
    $(".divscrolla").on("click", function(){
        $.ajax({
            dataType : "json",
            url:'db.php',
            type:'POST',
            data:{"data":$(this).val()},
            success:function(data){
                //consume the data in a assoc array manner
                //data[0]['name'] for first entry's name
            }
        });
    });
 }