I'm having trouble with a piece of code.
What I am trying to do is query the server and have it return me a random player from there that is within a level range of the player logged in. That part works. For those of you who notice- Yep I learned/amlearning off the Tutorials here and I still very much use what I saw there.
What isn't to my liking is that it has the option to return the player name of the player currently logged in ( i.e. you can choose yourself). I'm using this as part of a system that will let a player select an enemy player to do battle with from sort of a quicklist on the index so I'd like for their name not to be selectable even if I wont in the end let the player do combat with itself.
I have tried some different loops and if else type things but I can't get it to work right so I am linking it back at the very basics without my dirty coding attempts .
I'd also like to list @ 3-4 names. At the moment I'm just doing the query 3 times(one time shown)... I'm sure there's a better way to go here, but I'm still sort of bad at this so if you just felt like enlightening me it would be sweet if not I'm more concerned about the other problem.
If someone could please just take a minute and tell me how I would go about stopping it from picking my players name out of the mix from this simple form it would be much appreciated.
Thanks,
Rastan
Code: Select all
<?php
$playerinfo="SELECT * from player where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$maxlevel = $playerinfo3['level'] + 5;
$minlevel = $playerinfo3['level'] - 5;
if ($minlevel < 1)
{
$minlevel = 1;
}
$playerdisp ="SELECT * from player WHERE level < '$maxlevel ' AND level >= '$minlevel' order by rand() limit 1";
$playerdisp2 =mysql_query($playerdisp) or die("could get enemy player!");
$playerdisp3 =mysql_fetch_array($playerdisp2);
$enemychoice1= $playerdisp3['name'] ;
?>