Jump to content
MakeWebGames

Showing Only Odd or Even Id's


peterisgb

Recommended Posts

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();
?>
Link to comment
Share on other sites

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 by bluegman991
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by peterisgb
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Dominion
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...