I'm trying to modify a search function within a ezRPG game, and I'm just not sure how this search works so not sure how to make it do what I want.
The search form out of the box, has a drop down where the players can select 'alive' or 'dead' and it brings back results if hp>0 you're alive, hp=0 you're dead.
Well I've changed my game some, and now I have a new table that when you're dead the players ID is listed in the table for a set amount of time depending on what weapon was used against them.
So I need to change how the alive/dead search works.
I think I have the queries needed to actually pull the data, or at least close to having it. Just not sure how to incorporate them into this search.
Here is the search code that comes with the game.
This is the part where I need to modify
$query .= ($_GET['alive'] == "1")?"`hp` > 0 ":"`hp` = 0 ";
I need to change what alive==1 is looking at,
and I believe I need to add a $query .= ($_GET['dead'] == "0")
Code: Select all
case "search":
//Check in case somebody entered 0
$_GET['fromlevel'] = ($_GET['fromlevel'] == 0)?"":$_GET['fromlevel'];
$_GET['tolevel'] = ($_GET['tolevel'] == 0)?"":$_GET['tolevel'];
//Construct query
$query = "select `id`, `username`, `hp`, `maxhp`, `level` from `players` where `id`!= ? and ";
$query .= ($_GET['username'] != "")?"`username` LIKE ? and ":"";
$query .= ($_GET['fromlevel'] != "")?"`level` >= ? and ":"";
$query .= ($_GET['tolevel'] != "")?"`level` <= ? and ":"";
$query .= ($_GET['alive'] == "1")?"`hp` > 0 ":"`hp` = 0 ";
$query .= "limit 20";
//Construct values array for adoDB
$values = array();
array_push($values, $player->id); //Make sure battle search doesn't show self
if ($_GET['username'] != "")
{
array_push($values, "%".trim($_GET['username'])."%"); //Add username value for search
}
//Add level range for search
if ($_GET['fromlevel'])
{
array_push($values, intval($_GET['fromlevel']));
}
if ($_GET['tolevel'])
{
array_push($values, intval($_GET['tolevel']));
}
include("templates/private_header.php");
//Display search form again
echo "<fieldset>\n";
echo "<legend><b>Search for a player</b></legend>\n";
echo "<form method=\"get\" action=\"battle.php\">\n<input type=\"hidden\" name=\"act\" value=\"search\" />\n";
echo "<table width=\"100%\">\n";
echo "<tr>\n<td width=\"40%\">Username:</td>\n<td width=\"60%\"><input type=\"text\" name=\"username\" value=\"" . stripslashes($_GET['username']) . "\" /></td>\n</tr>\n";
echo "<tr>\n<td width=\"40%\">Level</td>\n<td width=\"60%\"><input type=\"text\" name=\"fromlevel\" size=\"4\" value=\"" . stripslashes($_GET['fromlevel']) . "\" /> to <input type=\"text\" name=\"tolevel\" size=\"4\" value=\"" . stripslashes($_GET['tolevel']) . "\" /></td>\n</tr>\n";
echo "<tr>\n<td width=\"40%\">Status:</td>\n<td width=\"60%\"><select name=\"alive\" size=\"2\">\n<option value=\"1\"";
echo ($_GET['alive'] == 1)?" selected=\"selected\"":"";
echo ">Alive</option>\n<option value=\"0\"";
echo ($_GET['alive'] == 0)?" selected=\"selected\"":"";
echo ">Dead</option>\n</select></td>\n</tr>\n";
echo "<tr><td></td><td><br /><input type=\"submit\" value=\"Search!\" /></td></tr>\n";
echo "</table>\n";
echo "</form>\n</fieldset>\n";
echo "<br /><br />";
echo "<table width=\"100%\">\n";
echo "<tr><th width=\"50%\">Username</th><th width=\"20%\">Level</th><th width=\"30%\">Battle</a></th></tr>\n";
$query = $db->execute($query, $values); //Search!
if ($query->recordcount() > 0) //Check if any players were found
{
$bool = 1;
while ($result = $query->fetchrow())
{
echo "<tr class=\"row" . $bool . "\">\n";
echo "<td width=\"50%\"><a href=\"profile.php?username=" . $result['username'] . "\">" . $result['username'] . "</a></td>\n";
echo "<td width=\"20%\">" . $result['level'] . "</td>\n";
echo "<td width=\"30%\"><a href=\"battle.php?act=attack&username=" . $result['username'] . "\">Attack</a></td>\n";
echo "</tr>\n";
$bool = ($bool==1)?2:1;
}
}
else //Display error message
{
echo "<tr>\n";
echo "<td colspan=\"3\">No players found. Try changing your search criteria.</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
for finding the dead players
SELECT medicalward.playerdead_ID, players.username, players.id
FROM players LEFT JOIN medicalward ON players.id = medicalward.playerdead_ID;
Then to find those alive, it would be anyone not listed in the medicalward table.
Does this sound right, and if so how do I add these queries so that 1 is ran when dead is selected and another ran when alive is selected?
Thanks