gpt4 book ai didi

php - Codeigniter查询结果row_array重复

转载 作者:行者123 更新时间:2023-11-28 23:42:16 25 4
gpt4 key购买 nike

我试图从数据库中获取一些记录,例如票务系统,它是从数据库结果下载的代码

$this->db->select('*');
$this->db->from('tickets');
$this->db->where('t_author_steam_id', $steamid);
$query = $this->db->get();

if($query->num_rows() > 0) {
$row = $query->row_array();

return $row;
}

但它是重复结果,并没有显示所有结果,而是只显示一个。 there is result

最佳答案

试试这个

方法01

$this->db->select('*');
$this->db->from('tickets');
$this->db->where('t_author_steam_id', $steamid);
$query = $this->db->get();
$result = $query->result_array();

if(!empty($result)) # this will act as $query->num_rows() > 0
{
return $result;
}

方法02

$this->db->select('*');
$this->db->from('tickets');
$this->db->where('t_author_steam_id', $steamid);
$this->db->group_by('t_author_steam_id'); # add this
$query = $this->db->get();
$result = $query->result_array();

if(!empty($result)) # this will act as $query->num_rows() > 0
{
return $result;
}

可见

<?php foreach($tickets as $items){ ?>
<tbody>
<th scope="row"><?php echo $items['t_id']; ?></th>
<th scope="row">
<?php if($items['t_lang'] == 1)
{
echo lang('polish');
} elseif($items['t_lang'] == 2) {
echo lang('english');
} ?>
</th>
<td><?php echo $items['t_title']; ?></td>
<td><?php echo $items['t_date']; ?></td>
<td>
<?php
if($items['t_status'] == 1)
{
echo '<span class="label label-info" id="status">'.lang('items-status-1').'</span>';
}
elseif($items['t_status'] == 2)
{
echo '<span class="label label-warning" id="status">'.lang('items-status-2').'</span>';
}
elseif($items['t_status'] == 3)
{
echo '<span class="label label-Success" id="status">'.lang('items-status-3').'</span>';
}?>
</td>
<td>Zobacz</td>
</tbody>
<?php } ?>

Method 1 is works fine. Problem is with in your code where you use foreach loop

关于php - Codeigniter查询结果row_array重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34174652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com