dqzlqfqeh845799833 2019-03-21 08:17 采纳率: 0%
浏览 55
已采纳

附加元素没有显示CSS ISSUE JAVASCRIPT PHP

I have experiencing some problems with fetching the grandchilds from my db table: referrals. However, it seems that my code can actually fetch the usernamee of my grandchilds. But it is not appearing below my child's line and there is no error in INSPECT.

Please see the OUTPUT image I attached here: Attached here are the images of the output of my code:

OUTPUT

This is the UPDATED database table name referrals: enter image description here

I used Javascript to fetch the data's inside "referrals" table

<!-- GENEOLOGY TREE -->
    <div class="tree">
       <?php $id = 1; ?>
          <ul>
             <li>
               <div id="parent_account"><a href="#"><img src="user.png" alt="Avatar" style="width:50px"/></br>Parent<?php echo $id; ?></a></div>
             </li>
        </ul>
      </div>
<!-- END OF GENOLOFY TREE -->


  <script>
$(document).ready(function(){
    // start get children
    var _id = "<?php echo $id ?>";
    var child = "";
    var child_id = [];
    var gchild_id = [];
    var count = 0;

    $.post('get_child_referrals.php', { id:_id }).done(function(response){
        var response = jQuery.parseJSON(response);
        var referred = response["referred"];
        var referred_len = response["referred"].length;
        if(referred_len > 0){
            child += "<ul>";
            for(var x = 0; x < referred_len; x++) {
                console.log(referred[x]["usernamee"]);
                count += 1;
                child_id[x] = referred[x]["id"];
                child += "<li id='child"+x+"'><a href="+x+"><img src='user.png' alt='Avatar' style='width:50px'/><br>Child "+referred[x]["usernamee"]+"</a></li>";
            }
            child += "</ul>";
            console.log(child);
            $("#parent_account").append(child);
            // start get grandchildren
        // console.log(child_id);
        var gchild_len = child_id.length;
        // console.log(gchild_len);
        for(i = 0; i < gchild_len; i++){
            gchild = "";
            _id = child_id[i];
            // console.log(_id);
            $.post('get_child_referrals.php', { id:_id }).done(function(response){
                gresponse = jQuery.parseJSON(response);
                greferred = gresponse["referred"];
                greferred_len = gresponse["referred"].length;
                if(greferred_len > 0){
                    gchild += "<ul>";
                    for(y = 0; y < greferred_len; y++) {
                        gchild_id[y] = greferred[y]["id"];
                        console.log(greferred[y]["usernamee"]);
                        gchild += "<li id='gchild"+y+"'><a href="+y+"><img src='user.png' alt='Avatar' style='width:50px'/><br>Child "+greferred[y]["usernamee"]+"</a></li>";
                    }
                    gchild += "</ul>";
                    console.log($("#child"+i).length);
                    console.log(gchild);
                    $("#child"+i).append(gchild);
                }
            });
        }
        // end get grandchildren
        }
    });
    // end get children
});
</script>​

get_child_referrals.php

include('connectdb.php');
$response = array();
$response["referred"] = array();
$id = $_POST['id'];
$sql = "SELECT * FROM referrals WHERE referral_id='$id'"; // MY RECRUITERS
$result = $conn->query($sql);
while($data = $result->fetch_assoc()) {
                array_push($response["referred"], $data);
}
echo json_encode($response);

For more info, this is my logs on my inspect console: enter image description here

  • 写回答

2条回答 默认 最新

  • dsa45664 2019-03-21 09:03
    关注

    First,Inspect for the username.Check if its coming in HTML.Sometimes, it is rendered but hidden.Secondly, just just console the child element,to confirm you are appending it to the right one.

    console.log($(child));

    I tried your code in my local, and got an output as in the pic.Check if its something that you want to get.

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错