想知道是否有更简单的方法可以做到这一点......
我有一个包含一堆行的表,需要根据名为“page_group”的 1 列上的特定值分别显示它们。现在,当我将结果的指针重置为零时它确实有效,但想知道是否有一种更简单的编码方式,因为至少有 15 个不同的部分对结果进行分组......?
//this is the query
$q_home = mysql_query("SELECT * FROM pages WHERE page_nav = 'No' ORDER BY page_group ASC");
//this would show results 1, showing all rows that have the value "sample1"
<h3>Result 1</h3>
<ul>
<?
while($r_nav = mysql_fetch_assoc($q_home)){
$group_folder = $r_nav['page_group'];
if ($r_access["$group_folder"] == "Yes" && $group_folder == 'sample1') {
$access = 'block;';
} else {
$access = 'none;';
} {;
echo '<li style="display:'.$access.'"><a href="'.$group_folder.'/'.$r_nav['page_url'].'.php">'.$r_nav['page_name'].'</a></li>';
}
}
?>
</ul>
//this would be result 2 showing all rows that have value "sample2"
<h3>Result 2</h3>
<ul>
<?
mysql_data_seek($q_home, 0);
while($r_nav2 = mysql_fetch_assoc($q_home)){
$group_folder = $r_nav2['page_group'];
if ($r_access["$group_folder"] == "Yes" && $group_folder == 'sample2') {
$access = 'block;';
} else {
$access = 'none;';
} {;
echo '<li style="display:'.$access.'"><a href="'.$group_folder.'/'.$r_nav2['page_url'].'.php">'.$r_nav2['page_name'].'</a></li>';
}
}
?>
</ul>