将字段存储在数组中并在php中显示 [英] Store fields in an array and display in php

查看:76
本文介绍了将字段存储在数组中并在php中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询,可读取所有不同的行。我想将其存储到数组中并显示每个循环使用。谁能帮我。

I have a query which fetch all distinct row. i want to store it to an array and display it back using for each loop. can anyone help me. thanks in advance.

这是我的代码:

//PREPARE QUERIES
//distinct effective dates
$allsched = $this->prepare("SELECT DISTINCT effective_date,status,in_use FROM `working_sched` WHERE `emp_id` = ? ");
$allsched->bind_param('i', $emp_id);
$allsched->execute();
$allsched->bind_result($distinctdate,$stat,$in_use);
$allsched->store_result();
$numrows = $allsched->num_rows;

//check if query turned empty!
if($numrows == 0){
    echo '<div id="error">Sorry no Working Schedule to be displayed for <b><i></i></b></div>';  
}else{
//if query returned TRUE
$effdatedist = array();
while($allsched->fetch()){
        $effdatedist[] =  $distinctdate; //store the effective dates in an array
        $effdatedist['stat'] = $stat;
}
$allsched->close();
}

在我的foreach循环中,我想显示以下内容

and in my foreach loop i want to display the following

foreach($effdatedist as $a){
    //display here
    date, status, in_use
}


推荐答案

while($effdatedist[] = $allsched->fetch(PDO::FETCH_ASSOC));

希望有帮助

这篇关于将字段存储在数组中并在php中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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