Nicholas Posted May 1, 2010 Share Posted May 1, 2010 ok everyone, im creating a newish gang central page kinda like some userlists but im experiencing some problems it works in ASC but it dont in DESC and i cant figure out why... can someone help please? also if you can... could you update it little more so it works with the Members section? as i cant figire it out... it doesnt work correctly. here is the code (gangcentral.php) <?php include_once(DIRNAME(__FILE__) .'/globals.php'); $sort = (isset($_GET['sort']) && is_numeric($_GET['sort'])) ? abs(@intval($_GET['sort'])) : 'ASC'; $orderby = (isset($_GET['orderby']) && ctype_alpha($_GET['orderby'])) ? strip_tags(mysql_real_escape_string($_GET['orderby'])) : 'gangID'; echo "<h3>Gangs</h3>"; echo " [url='?by=".$orderby."&sort=ASC']Ascending[/url]| [url='?by=".$orderby."&sort=DESC']Descending[/url]"; $gang = $db->query(sprintf("SELECT g.*,u.* FROM gangs g LEFT JOIN users u ON g.gangPRESIDENT=u.userid ORDER BY %s %s LIMIT 1000", $orderby, $sort)); $cnt= $db->query(sprintf("SELECT g.*,u.* FROM gangs g LEFT JOIN users u ON g.gangID=u.username ORDER BY %s %s LIMIT 1000", $orderby, $sort)); $sort = "".$sort; echo "<table cellspacing=0 border=1 cellpadding=3 class=table width=95%> <tr> <th class=h align=center>[url='?orderby=gangID&sort=$sort']Gang ID[/url]</th> <th class=h align=center>[url='?orderby=gangNAME&sort=$sort']Gang Name[/url]</th> <th class=h align=center>Members</th> <th class=h align=center>[url='?orderby=username&sort=$sort']Leader[/url]</th> <th class=h align=center>[url='?orderby=gangRESPECT&sort=$sort']Gang Respect[/url]</th> </tr>"; while($gangdata = $db->fetch_row($gang)) { echo "<tr> <td align=center>[{$gangdata['gangID']}]</td> <td align=center>[url='gangs.php?action=view&ID=".abs(intval($gangdata[']{$gangdata['gangNAME']}[/url]<td align=center>"; $cnt=mysql_query("SELECT username FROM users WHERE gang=".abs(intval($gangdata['gangID']))."",$c); print mysql_num_rows($cnt)."</td> <td align=center><a href='viewuser.php?u=".abs(intval($gangdata['userid']))."'>".htmlentities($gangdata['username'])."</td> <td align=center>".number_format($gangdata['gangRESPECT'])."</td> </tr>"; } echo "</table>"; $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
Danny696 Posted May 1, 2010 Share Posted May 1, 2010 (isset($_GET['sort']) && is_numeric($_GET['sort'])) ? abs(@intval($_GET['sort'])) Is your problem, its not numeric, its a string. Quote Link to comment Share on other sites More sharing options...
Nicholas Posted May 1, 2010 Author Share Posted May 1, 2010 ok i done $sort = (isset($_GET['sort']) && ctype_alpha($_GET['sort'])) ? strip_tags(mysql_real_escape_string($_GET['sort'])) : 'ASC'; and it works now thanks. but is there any chance you could help me with the Members bit? or do you think i have to add gangMEMBERS into gangs section and edit it to show the number of gang members in the gang to do it with the ASC and DESC stuff? if thats understandable? as i tired <th class=h align=center>[url='?orderby=$cnt&sort=$sort']Members[/url]</th> but it didnt work the link i got was ?orderby=Resource id #12&sort= ASC some reason Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.