日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

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

發布時間:2023/12/20 php 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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');

查看代碼:

<?php echo $searchingtyp['searchtype_name'];?>

請檢查下面的圖像,我已經顯示了此代碼的輸出,并且我還畫了我需要的輸出,謝謝,請幫助我.謝謝

解決方法:

只需存儲您的姓氏,并且僅在新名稱與其不同時才打印它.發生這種情況時,我們還將創建新列表,以便每個組具有不同的列表.

// 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;

?>

?>

  • <?php echo $searchingtyp['searchtype_name'];?>

// 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

總結

以上是生活随笔為你收集整理的php循环输出标题,php-如何通过循环在同一标题下分组数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。