php循环输出标题,php-如何通过循环在同一标题下分组数据

我试图从两个联接表中获取数据,从一个表中我收集列表标题,从第二个联接表中我收集列表数据.

型号代码:

function view_searching_type_items()

{

$this->db->select("searching_type.searchtype_name, search_type_item.st_item_id_pk, search_type_item.searchtype_itemname");

$this->db->from('searching_type');

$this->db->join('search_type_item', 'search_type_item.st_id_fk = searching_type.st_id_pk');

$query = $this->db->get();

return $query->result_array();

}

控制器:

$url1 = 'http://localhost/pakistanmenu/index.php/Restaurant/ViewSearchingTypeItems';

$curl_hand = curl_init($url1);

curl_setopt($curl_hand, CURLOPT_TIMEOUT, 5);

curl_setopt($curl_hand, CURLOPT_CONNECTTIMEOUT, 5);

curl_setopt($curl_hand, CURLOPT_RETURNTRANSFER, true);

$data1 = curl_exec($curl_hand);// json_decode($data)

curl_close($curl_hand);

$result['searchingtype'] = (array) json_decode($data1,true);

$this->load->view('header');

$this->load->view('index',$result);

$this->load->view('footer');

查看代码:

请检查下面的图像,我已经显示了此代码的输出,并且我还画了我需要的输出,谢谢,请帮助我.谢谢

QOVmU.png

解决方法:

只需存储您的姓氏,并且仅在新名称与其不同时才打印它.发生这种情况时,我们还将创建新列表,以便每个组具有不同的列表.

// Define our test variable

$lastName = null;

foreach ($searchingtype as $searchingtyp):

?>

if ($lastName != $searchingtyp['searchtype_name']):

// It's not the same name

if ($lastName != null):

// Close the previous list (except from the first iteration).

?>

endif;

?>

?>

// Store the current name so we can check again in the next iteration

$lastName = $searchingtyp['searchtype_name'];

endif;

?>

// The rest of your code.. just move the

after the loop.

标签:php,codeigniter,loops

来源: https://codeday.me/bug/20191012/1903106.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值