简体   繁体   English

如何显示相同列但具有不同值的结果

[英]How to display results of same column but have different values

Here I'm returning data from my database which have a title_heading column and it has a title column.在这里,我从我的数据库中返回数据,其中有一个 title_heading 列和一个 title 列。

 id     title_heading    title
 
 1     HTML Tutorial     Home
 2     HTML Tutorial     Overview
 3     HTML References   Tags 
 4     HTML References   Events

but now I wanted to show the results like this in my view:但现在我想在我看来显示这样的结果:

**HTML Tutorial**
   Home
   Overview

**HTML References** 
   Tags
   Events

i have two idea on this.. first normalize that table into two table..我对此有两个想法..首先将该表规范化为两个表..

heading : [id,name] subTitle : [id, name, heading_id]标题:[id,名称] 子标题:[id,名称,heading_id]

then you make oneToMany Relationship in laravel然后你在 Laravel 中建立 oneToMany 关系

https://laravel.com/docs/5.7/eloquent-relationships#one-to-many https://laravel.com/docs/5.7/eloquent-relationships#one-to-many

second you can use nested loop it and push it into array..第二,您可以使用嵌套循环并将其推入数组..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Laravel 搜索结果的相同 column2 值下分组并显示不同的 column1 值 - Group and Display different column1 values under the same column2 values from Laravel Search Results 如何显示来自具有相同列名的两个不同表的结果 - How to display results from two different tables with the same column names 如何仅显示指定列中没有NULL值的结果? - How do I only display results that do not have NULL values from a specified column? 如何在PHP中的B列中显示具有相同值的列A的所有结果 - How to display all results from columns A with same values in Column B in php 如何从一个具有不同值的列同时从弹性搜索中获取结果? - How can I fetch results from elastic search from one column with different values at the same time? 显示具有相同列值的不同行的多个值 - Display multiple values from different rows with same column value 我想用不同的值mysql显示两次相同的列 - I want to display same column twice with different values mysql 如何在mysql的同一列中计算不同的值? - How to count different values in a same column in mysql? 如何根据值将mysql结果显示到不同的列中 - how to display mysql results into different columns based off of values 如何根据mysql返回的不同值显示php结果 - How to display php results based on different values returned from mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM