peterisgb Posted March 11, 2013 Share Posted March 11, 2013 I've tried to edit this page to get it to show only even or odd id's but i ain't doing something right, could i have a little help with this please. ty <?php include "globals.php"; global $db,$ir,$c,$userid,$h; $db->query("UPDATE users SET lastpage='Userlist' WHERE userid=$userid"); $_GET['st'] = abs((int) $_GET['st']); $st=($_GET['st']) ? $_GET['st'] : 0; $by=($_GET['by']) ? $_GET['by'] : 'userid'; $ord=($_GET['ord']) ? $_GET['ord'] : 'ASC'; $cnt=mysql_query("SELECT userid FROM users",$c); $membs=mysql_num_rows($cnt); $pages=(int) ($membs/100)+1; if($membs % 100 == 0) { $pages--; } print "Pages: "; for($i=1;$i <= $pages;$i++) { $stl=($i-1)*100; print "<a href='userlist.php?st=$stl&by=$by&ord=$ord'>$i</a> "; } print "<br /> Order By: <a href='userteam.php?st=$st&by=userid&ord=$ord'>User ID</a> | <a href='userteam.php?st=$st&by=username&ord=$ord'>Username</a> | <a href='userteam.php?st=$st&by=Even&ord=$ord'>Even users</a> | <a href='userteam.php?st=$st&by=Odd&ord=$ord'>Odd Users</a> | <a href='userteam.php?st=$st&by=level&ord=$ord'>Level</a> | <a href='userteam.php?st=$st&by=gymlevel&ord=$ord'>Gym Level</a><br /> <a href='userteam.php?st=$st&by=$by&ord=asc'>Ascending</a> | <a href='userteam.php?st=$st&by=$by&ord=desc'>Descending</a><br /><br /> "; print "<h3>Userlist</h3>"; $q=$db->query = 'SELECT `username` FROM `users` WHERE ( `userid` % 2 = '.( array_key_exists ( 'odd', $_GET ) ? 1 : 0 ).' ))'; $no1=$st+1; $no2=$st+100; print "Showing users $no1 to $no2 by order of $by $ord. <table width=90% cellspacing=1 class='table'> <tr style='background:gray'> <th>ID</th> <th>Links</th> <th>Name</th> <th>Level</th> <th>Gym Level</th> <th>Smoking Level</th> <th>Gender</th> <th>Race</th> <th>Online</th> </tr>"; while($r=$db->fetch_row($q)) { $d=""; if($r['donatordays']) { $r['username'] = "<font color='{$r['colour']}'>{$r['username']}</font>";$d="<img src='donator.gif' alt='Donator: {$r['donatordays']} Days Left' title='Donator: {$r['donatordays']} Days Left' />"; } $name=$r['username']; if($r['user_level']== 2) { $staff="<img src='images/owner.gif' alt='Game Staff' />"; } if($r['user_level']== 3) { $staff="<img src='images/owner.gif' alt='Game Staff' />"; } if($r['user_level']== 4) { $staff="<img src='images/owner.gif' alt='Game Staff' />"; } if($r['user_level']== 5) { $staff="<img src='images/owner.gif' alt='Game Staff' />"; } if($r['user_level']== 1) { $staff=""; } if($r['userid']==1) { $staff="<img src='images/owner.gif' alt='Game Staff' /><img src='images/admin.gif' alt='Game Owner' />"; } if ($r['sidename'] == 0) { $sides="N/A"; } if ($r['sidename'] == 1) { $sides="<img src='hacker.gif' title='Hackers' width='15' height='15'><b> <u><font color='cadetblue'>Hackers</font></u></b>"; } if ($r['sidename'] == 2) { $sides="<img src='police.gif' title='Police' width='15' height='15'><b> <u><font color='red'>Police</font></u></b>"; } print " <tr> <td>{$r['userid']}</td> <td><small>[<a href='viewuser.php?u={$r['userid']}'>View</a>] [<a href='attack.php?ID={$r['userid']}'>Attack</a>] [<a href='mailbox.php?action=compose&ID={$r['userid']}'>Mail</a>]</small></td> <td><a href='viewuser.php?u={$r['userid']}'>{$r['gangPREF']} <font color='{$r['colour']}'> {$r['username']} </font> $d $staff</a></td> <td>{$r['level']}</td> <td>{$r['gymlevel']}</td> <td>{$r['smoking']}</td> <td>{$r['gender']}</td> <td>{$r['race']}</td><td>"; if($r['laston'] >= time()-15*60) { print "<font color=green><b><img src='images/online.png'></b></font>"; } else { print "<font color=red><b><img src='images/offline.png'></b></font>"; } print "</td></tr>"; } print "</table>"; $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
bluegman991 Posted March 12, 2013 Share Posted March 12, 2013 (edited) Are you getting any errors at all? What happens when you run this code? It looks like on line 36 you have 1 too many closing parenthesis. Edit: Looking at line 36 again. I noticed the query isn't even being executed. Because you are attempting to define a property, instead of calling $db->query as a method. That being said try this as line 36 $q=$db->query('SELECT `username` FROM `users` WHERE ( `userid` % 2 = '.( array_key_exists ( 'odd', $_GET ) ? 1 : 0 ).' )'); Edited March 12, 2013 by bluegman991 Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 12, 2013 Author Share Posted March 12, 2013 that kinda works, defo shows users, but all id's and links dont work. just displays username Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 12, 2013 Author Share Posted March 12, 2013 the idea is its suppose to be like the normal userlist page, but when clicking odd/even in the selection list it displays evens and odds. Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 12, 2013 Author Share Posted March 12, 2013 well my game runs on all odd ID's are hackers and all even ID's are police. they fight eachother gaining points for there team. hackers vs police, its become quite successfull for me, but users are saying that they would like a page displaying all the users in the opposite team, i think it would be a good thing to have for me theme Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 12, 2013 Author Share Posted March 12, 2013 well the page just diplays the users, but nothing else, can't click them or anything, no other information is being taken by the database into the page. Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 12, 2013 Author Share Posted March 12, 2013 (edited) figured it out, i just looked at it. $q=$db->query('SELECT `username` FROM `users` WHERE ( `userid` % 2 = '.( array_key_exists ( 'odd', $_GET ) ? 1 : 0 ).' )'); changed that to this $q=$db->query('SELECT * FROM `users` WHERE ( `userid` % 2 = '.( array_key_exists ( 'odd', $_GET ) ? 1 : 0 ).' )'); now how would i go about making it show only odd id's Edited March 12, 2013 by peterisgb Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted March 12, 2013 Share Posted March 12, 2013 Not too sure exactly how lol but maybe using the mod() function may help if you can implement it some how Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 12, 2013 Author Share Posted March 12, 2013 Not too sure exactly how lol but maybe using the mod() function may help if you can implement it some how yeah, it sounds like an idea, however, my coding skills are quite limited at the moment, haven't quite got the nak of switch functions yet. Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted March 12, 2013 Share Posted March 12, 2013 You can maybe add an if statement to your query like: if (isset ($_GET["buy"]) && $_GET["buy"] == "odd") $db->query("SELECT * FROM users WHERE MOD( userid, 2 ) =1"); else //run your regular query you had here That should return odd userids Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 12, 2013 Author Share Posted March 12, 2013 You can maybe add an if statement to your query like: if (isset ($_GET["buy"]) && $_GET["buy"] == "odd") $db->query("SELECT * FROM users WHERE MOD( userid, 2 ) =1"); else //run your regular query you had here That should return odd userids so if i am right it should be like if (isset ($_GET["buy"]) && $_GET["buy"] == "odd") $db->query("SELECT * FROM users WHERE MOD( userid, 2 ) =1"); else $q=$db->query('SELECT * FROM `users` WHERE ( `userid` % 2 = '.( array_key_exists ( 'odd', $_GET ) ? 1 : 0 ).' )'); because if its this it shows evens either way Quote Link to comment Share on other sites More sharing options...
InternalExpertCoding Posted March 12, 2013 Share Posted March 12, 2013 Kyle beat me to it lol Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 12, 2013 Author Share Posted March 12, 2013 ok it does work, i was doing it wrong, lol, thanks so much for this, great help guys. spent about 2 weeks trying to get this to work, my final option was to seek help here lol, thanks Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted March 12, 2013 Share Posted March 12, 2013 nvm Too short Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 12, 2013 Author Share Posted March 12, 2013 Now just need to get this thread deleted, dont want to many people to steal my idea lol Quote Link to comment Share on other sites More sharing options...
Aventro Posted March 12, 2013 Share Posted March 12, 2013 This isn't a free private support board. If you want these kind of features only to your own game, you'll either code them yourselves or hire someone to do it, is my opinion at least. Quote Link to comment Share on other sites More sharing options...
Spudinski Posted March 12, 2013 Share Posted March 12, 2013 This isn't a free private support board. If you want these kind of features only to your own game, you'll either code them yourselves or hire someone to do it, is my opinion at least. Yea, and even so, this is a pretty ... well, "unsustainable", idea in any case. Mapping/reference IDs are not supposed to be mangled like this. A resource has an identifier, a definite location. You would have been much better off using some other method of identifying the two classes. Usually, when something seems complex or implausible, it's most likely that you're doing it wrong. Quote Link to comment Share on other sites More sharing options...
Dominion Posted March 12, 2013 Share Posted March 12, 2013 (edited) You would have been much better off using some other method of identifying the two classes. Depending how wide spread this method is used throughout the game I would have to agree here. It would make class specific features much easier to add for you in the future. Edited March 12, 2013 by Dominion Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 12, 2013 Author Share Posted March 12, 2013 well i didnt know anyway of dividing all the users into 2 groups. Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted March 13, 2013 Share Posted March 13, 2013 Im just curious though what exactly is wrong with mod(), is it resource intensive or what, or are you just talking about the separation or id for particular classes? Personally I would have gone with either: A. Letting a user choose their class or.... B. What I have done in the past is hold classes in an array and it randomly puts them in a class. Option b was quite simple and pretty effective and it was pretty balanced, I mean at most I had maybe a difference of 5 between my classes but to each their own Quote Link to comment Share on other sites More sharing options...
Aventro Posted March 13, 2013 Share Posted March 13, 2013 So, depending on when I register I need to stick upon being either a cop or hackzor? Seems legit. Quote Link to comment Share on other sites More sharing options...
Spudinski Posted March 13, 2013 Share Posted March 13, 2013 Amended: Add class column to table, let users choose. Also, depending on the amount of classes and their relationships with other things like stats(etc.), use another table for them. Quote Link to comment Share on other sites More sharing options...
peterisgb Posted March 13, 2013 Author Share Posted March 13, 2013 this is pretty good, for me i didnt let the users choose what team they could join as they would all join one team which would make it unfair on the other team so i didnt let the user choose. makes it more fair Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted March 14, 2013 Share Posted March 14, 2013 this is pretty good, for me i didnt let the users choose what team they could join as they would all join one team which would make it unfair on the other team so i didnt let the user choose. makes it more fair I Think if you set it up the way Guest or Spud has mentioned it may be less invasive on your machine for example we'll use your userlist script posted here, it is just one less query your running since you are already grabbing all the users data from the db (which you should look into selected only what you want to show). Or you can take he approach I did in which you create a column like class as Guest said and store the values in an array and insert it randomly like: $class = array("Cops", "Hackers"); $p = array_rand($class); //here is your insert in the db for registration so add in class = {$p['class']} Its that simple, you dont have to make make any extra tables to store your classes unless you wanted to go above and beyond and possible do stat changes depending on the class a user is in. 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.