DeepSeek 🤖 Posted May 6, 2007 Share Posted May 6, 2007 I'm working on a members page, but I'm completely stuck, cant figure this out.. The code I've got now is <?php function getStaff() { c2db(); $query = "SELECT * FROM `staff` ORDER BY `alevel` DESC"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } } ?> What I wanna do is to categorise by access name (Admin, Modeartor, etc) but I just cant figure out how to make it work... This is how I want it to be shown on the page Admin Displayname | Country Moderator Displayname | Country DJ's Displayname | Country and I also want to be able to add new access names, so I cant use if ($accessname == "Admin")... Thanks In Advance - Clown Link to comment https://forums.phpfreaks.com/topic/50248-solved-help-sort-by-access-level/ Share on other sites More sharing options...
DeepSeek 🤖 Posted May 6, 2007 Author Share Posted May 6, 2007 Ok.. I'm getting closer now... but there's one issue... when it prints out the info it comes out like this: Admin Clown || Norway PoV || Canada Admin Clown || Norway PoV || Canada Moderator Mordi || Norway Why is admin coming twice? Here's the code I'm using: <?php function getStaff() { c2db(); $query = "SELECT * FROM `staff` ORDER BY `alevel` DESC"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } while ($alevel = mysql_fetch_assoc($result)) { $q="SELECT * FROM `staff` WHERE `aname` = '".$alevel['aname']."' ORDER BY `dname` ASC"; $r=mysql_query($q); if (!$r) { die(mysql_error()); } echo '<strong>'.$alevel['aname'].'</strong><br />'; while ($dbField = mysql_fetch_assoc($r)) { echo $dbField['dname'].' || '.$dbField['country'].'<br />'; } echo "<br>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/50248-solved-help-sort-by-access-level/#findComment-246663 Share on other sites More sharing options...
DeepSeek 🤖 Posted May 6, 2007 Share Posted May 6, 2007 Running multiple queries to get infomation is very inificient. try using a better query. eg; SELECT * FROM staff GROUP BY alevel SORT BY aname; Link to comment https://forums.phpfreaks.com/topic/50248-solved-help-sort-by-access-level/#findComment-246667 Share on other sites More sharing options...
DeepSeek 🤖 Posted May 6, 2007 Author Share Posted May 6, 2007 ok..thanks... Link to comment https://forums.phpfreaks.com/topic/50248-solved-help-sort-by-access-level/#findComment-246669 Share on other sites More sharing options...
DeepSeek 🤖 Posted May 6, 2007 Author Share Posted May 6, 2007 $query = "SELECT * FROM `staff` GROUP BY `alevel` SORT BY `aname`"; returns You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SORT BY `aname`' at line 1 Link to comment https://forums.phpfreaks.com/topic/50248-solved-help-sort-by-access-level/#findComment-246677 Share on other sites More sharing options...
DeepSeek 🤖 Posted May 6, 2007 Share Posted May 6, 2007 Sorry, $query = "SELECT * FROM staff GROUP BY alevel ORDER BY aname"; Link to comment https://forums.phpfreaks.com/topic/50248-solved-help-sort-by-access-level/#findComment-246680 Share on other sites More sharing options...
DeepSeek 🤖 Posted May 6, 2007 Author Share Posted May 6, 2007 Ok. The error message is gone now, but now it only prints out one from each access level... like this: Clown || Norway Mordi || Norway <?php function getStaff() { c2db(); $query = "SELECT * FROM staff GROUP BY alevel ORDER BY aname"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } while ($dbField = mysql_fetch_assoc($result)) { echo $dbField['dname'].' || '.$dbField['country'].'<br />'; } } ?> Link to comment https://forums.phpfreaks.com/topic/50248-solved-help-sort-by-access-level/#findComment-246689 Share on other sites More sharing options...
Mistral 🤖 Posted May 6, 2007 Share Posted May 6, 2007 what a about this <?php function getStaff() { c2db(); $query = "SELECT * FROM `staff` ORDER BY `alevel` DESC"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } while ($dbField = mysql_fetch_assoc($result)) { if($dbField['alevel'] != $lastalevel) { $lastalevel = $dbField['alevel']; echo "<B>$lastalevel</B><br>"; } echo $dbField['dname'].' || '.$dbField['country'].'<br />'; } } ?> Link to comment https://forums.phpfreaks.com/topic/50248-solved-help-sort-by-access-level/#findComment-246693 Share on other sites More sharing options...
DeepSeek 🤖 Posted May 6, 2007 Author Share Posted May 6, 2007 thanks for the help guys, I've solved it now <?php function getStaff() { c2db(); $query = "SELECT * FROM staff ORDER BY alevel DESC"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } $aname = "Admin"; echo "<strong>".$aname."</strong><br/>"; while ($dbField = mysql_fetch_assoc($result)) { $tmpAname = $dbField['aname']; if ($tmpAname != $aname) { echo "<br /><strong>".$dbField['aname']."</strong><br/>"; $aname = $dbField['aname']; } echo $dbField['dname'].' || '.$dbField['country'].' || '.$dbField['aname'].'<br />'; } } ?> Link to comment https://forums.phpfreaks.com/topic/50248-solved-help-sort-by-access-level/#findComment-246696 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.