Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在公用名称下的列表中显示数据库中需要配对的两个参数_Php_Arrays - Fatal编程技术网

Php 在公用名称下的列表中显示数据库中需要配对的两个参数

Php 在公用名称下的列表中显示数据库中需要配对的两个参数,php,arrays,Php,Arrays,我有一个ban list数据库系统,它保存规则类型(类别),然后是它的特定规则 我有多个具有相同规则类型名称的规则,但我无法确定如何使我的网站在规则类型的名称标题下显示类别的两组规则 示例:我有两个类别: 禁令规则 行为准则 但是我的ban规则在我的数据库中有两行,我不知道如何在标题“ban规则”下以列表格式显示它们 我会将查询结果转换为更易于输出的格式,然后循环生成所需的html结构。像这样的 $sql = "SELECT * FROM minecraft"; $result = mysql_

我有一个ban list数据库系统,它保存规则类型(类别),然后是它的特定规则

我有多个具有相同规则类型名称的规则,但我无法确定如何使我的网站在规则类型的名称标题下显示类别的两组规则

示例:我有两个类别:

  • 禁令规则
  • 行为准则 但是我的ban规则在我的数据库中有两行,我不知道如何在标题“ban规则”下以列表格式显示它们


    我会将查询结果转换为更易于输出的格式,然后循环生成所需的html结构。像这样的

    $sql = "SELECT * FROM minecraft";
    $result = mysql_query($sql);
    $rules = array();
    
    if(mysql_num_rows($result) > 0 ) {
      while($row = mysql_fetch_assoc($result)) {
        $type = $row['rule_type']
        $rules[$type][] = $row['rule'];
      }
    }
    
    if(!empty($rules)) {
      // outout html that precedes the list of rules
    
      foreach($rules as $type => $rule_names) {
        // output the html for each rule group
    
        foreach($rule_names as $rule_name) {
          // output the html for each rule
        }
      }
    }
    
    $sql = "SELECT * FROM minecraft";
    $result = mysql_query($sql);
    $rules = array();
    
    if(mysql_num_rows($result) > 0 ) {
      while($row = mysql_fetch_assoc($result)) {
        $type = $row['rule_type']
        $rules[$type][] = $row['rule'];
      }
    }
    
    if(!empty($rules)) {
      // outout html that precedes the list of rules
    
      foreach($rules as $type => $rule_names) {
        // output the html for each rule group
    
        foreach($rule_names as $rule_name) {
          // output the html for each rule
        }
      }
    }