dongshao2967 2017-07-27 22:04
浏览 17

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

I have a ban list database system that holds the Rule type(category) and then a specific rule for it.

I have multiple rules with the same rule type name, but I cannot figure out how to make my website display both sets of rules for the category, underneath the Name header of the rule type.

Example: I have two categories:

  1. Ban rules.
  2. Conduct rules.

but my ban rules has 2 rows in my database and I cannot figure out how to display them both in a list format underneath the title "Ban Rules".

<?php
$sql = "SELECT * FROM minecraft";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

if(mysql_num_rows($result) > 0 ) {
    echo "<div class='row'>";
    echo "<div class='col-lg-12'>";
    echo "<ul style='background-color:transparent;' class='list-group-item'>";
    echo "Rules:";
    echo "</ul>";
}
while($row = mysql_fetch_array($result)) {
    echo "<div class='row'>";
    echo "<div class='col-lg-12'>";
    echo "<li style='background-color:transparent;' class='list-group-item'>";
    echo $row['rule_type'];
    echo "</li>";
            //I need this one to produce two results underneath the 'Rule Type header on my list, but it only gives me one of the two results i need!//'
    echo "<li style='background-color:transparent;' class='list-group-item'>";
    echo  $row['rule'];
    $row['rule'](2);
    echo "</li>";
}
  • 写回答

1条回答 默认 最新

  • duandeng2265 2017-07-27 23:23
    关注

    I would translate the query result into a format that was easier to output and then loop over that to generate the html structure that you want. Something like this.

    $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
        }
      }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题