循环到php数组的每一行 [英] Loop to every each row of php array

查看:96
本文介绍了循环到php数组的每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我这里有两套代码

Hello I have 2 sets of code here and here it is

Ajax

/* Loop and Get Data from database to create a table */
$(document).ready(function () { 
   $('#btngenerate').click(function(e){
       var d1 = $('#startdate').val();
       var d2 = $('#enddate').val();
         $.ajax({
            url: 'queries/qryTITO.php',
            type: "POST",
            datatype: 'json',
            data: ({startdate: d1,enddate: d2}),
            success: function(data){
                console.log(data);
            }
        });  
   });
});

这是PHP

<?php
    require 'conn.php';
    $startdate = $_POST['startdate'];
    $enddate   = $_POST['enddate'];
    $sql       = "SELECT vdate FROM tablename WHERE date(vdate) between date('" . $startdate . "') and date('" . $enddate . "')";
    $result    = mysqli_query($con,$sql);
    $row       = mysqli_fetch_row($result);
    $jsonData = array();
    while ($array = mysqli_fetch_row($result)) {
        $jsonData[] =  $array;
    }
    echo json_encode($jsonData);
    mysqli_close($con);
?>

这是我的问题.我试图将值返回给jquery,以便创建HTML表.实际上它正在工作,这就是输出

here is my question. I am trying to return the value back to the jquery so I can create a HTML Table. actually it is working and this is the output

我的问题是如何为该数据创建HTML表?

My question here is how can I make an HTML table for that data?

这是我得到的错误

推荐答案

尝试一下

$(document).ready(function () { 
   $('#btngenerate').click(function(e){
       var d1 = $('#startdate').val();
       var d2 = $('#enddate').val();
         $.ajax({
            url: 'queries/qryTITO.php',
            type: "POST",
            datatype: 'json',
            data: ({startdate: d1,enddate: d2}),
            success: function(data){
                    $.each(data,function(){
                        $('tr').append("<td>"+this+"</td>")
                    });
            }
        });  
   });
});

这是> 样本小提琴 .

这篇关于循环到php数组的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆