简体   繁体   English

是否可以从行内容过滤/分离MySQL中的MySQL数据?

[英]Is it possible to Filter / Seperate Data from MySQL in PHP from a rows content?

What I am trying to achieve is a way to filter results from a table from the values in aa given row. 我试图实现的是一种从给定行中的值中过滤表结果的方法。

For Example: If I have a table for school times for multiple schools. 例如:如果我有多个学校的上课时间表。 I want to get all the data from the table and then have it separate into the schools. 我想从表格中获取所有数据,然后将其分别放入学校。

So what would be the best way of doing this that on a webpage the data can be separated by headers for the different fields like separate the schools with header of the school names? 那么最好的方法是,在网页上用不同字段的标头分隔数据,例如用学校名称的标头分隔学校?

I guess first of all it would be good to extend your SQL query with the GROUP BY function or at least the ORDER function. 我想首先,最好使用GROUP BY函数或至少使用ORDER函数扩展SQL查询。 After that you have to do a so called group change in your php code like in the following example code: 之后,您必须在php代码中进行所谓的组更改,如以下示例代码所示:

$school = '';
foreach ($data as $row) {
    // here 's the group change
    if ($school != $row['school_name'])) {
        $school = $row['school_name'];

        // header output
        echo $row['school_name'];
    }

    // output of the other data
    echo $row['blah'];
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM