php - Displaying two parameters from database that need to be paired together in a list under the common name -
i have ban list database system holds rule type(category) , specific rule it.
i have multiple rules same rule type name, cannot figure out how make website display both sets of rules category, underneath name header of rule type.
example: have 2 categories:
- ban rules.
- conduct rules.
but ban rules has 2 rows in database , cannot figure out how display them both in list format underneath title "ban rules".
<?php $sql = "select * 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 1 produce 2 results underneath 'rule type header on list, gives me 1 of 2 results need!//' echo "<li style='background-color:transparent;' class='list-group-item'>"; echo $row['rule']; $row['rule'](2); echo "</li>"; }
i translate query result format easier output , loop on generate html structure want. this.
$sql = "select * 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 precedes list of rules foreach($rules $type => $rule_names) { // output html each rule group foreach($rule_names $rule_name) { // output html each rule } } }
Comments
Post a Comment