Jump to content

cdoyle

Members
  • Posts

    164
  • Joined

  • Last visited

Everything posted by cdoyle

  1. I searched the page and found this //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'])); }
  2. OK, I moved the echo to before that, and it now displays this on the page select * from `players` where `id`!= ? and `hp` > 20 limit 20
  3. I'm not sure what you mean? I tried echo "$query"; and it just displayed 'object' the code has while ($result = $query->fetchrow()) If I used $result['city_id'] I get the ID number from the players table from field City_ID. I'm just not sure how to get the city name from the City table and display it.
  4. Hi, I'm trying to modify a ezRPG page, to include a field from an additional table I created. In the 'players' table I added a field named 'City_ID' and I've added a new table called Cities, that holds all the Cities. It's fields are City_ID, City_Name. In the code below, it outputs from $result the info about the player. I want the City Name to appear in this part of the code echo "<td width=\"20%\">" . $result['City_Name'] ."</td>\n"; I'm thinking I need to do a Left Join? But I'm not sure where, I need to do it. I thought maybe here $query = "select * from `players` where `id`!= ? and "; but I'm not sure.. Here is the part of the code I think it needs to go, I wanted to attach the page, but I get an error when I try. 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 * 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` > 20 ":"`hp` < 20 "; $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 "<legend><b>Search for a player</b></legend>\n"; echo "<form method=\"get\" action=\"battle2.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"; echo "<br /><br />"; echo "<table width=\"100%\">\n"; echo "<tr><th width=\"30%\">Username</th><th width=\"20%\">Level</th><th width=\"20%\">Location</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=\"30%\"><a href=\"profile.php?username=" . $result['username'] . "\">" . $result['username'] . "</a></td>\n"; echo "<td width=\"20%\">" . $result['level'] . "</td>\n"; [b]echo "<td width=\"20%\">" . $result['City_Name'] ."</td>\n";[/b] echo "<td width=\"30%\"><a href=\"battle2.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"; include("templates/private_footer.php"); break; default: include("templates/private_header.php"); //The default battle page, giving choice of whether to search for players or to target one echo "<legend><b>Search for a player</b></legend>\n"; echo "<form method=\"get\" action=\"battle2.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\" /></td>\n</tr>\n"; echo "<tr>\n<td width=\"40%\">Level</td>\n<td width=\"60%\"><input type=\"text\" name=\"fromlevel\" size=\"4\" /> to <input type=\"text\" name=\"tolevel\" size=\"4\" /></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\" selected=\"selected\">Alive</option>\n<option value=\"0\">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"; echo "<br /><br />\n"; echo "<legend><b>Attack a player</b></legend>\n"; echo "<form method=\"get\" action=\"battle2.php?act=attack\">\n<input type=\"hidden\" name=\"act\" value=\"attack\" />\n"; echo "Username: <input type=\"text\" name=\"username\" /><br />\n"; echo "<input type=\"submit\" value=\"Battle!\" />\n"; echo "</form>\n"; include("templates/private_footer.php"); break; } ?>
  5. Does anyone else have any suggestions? I'm totally stuck on this There has to be a way, to pull up a list of cities based on the players level. Then make it so when the user clicks on a city, it updates the city_id in the players table. The select pulls the correct cities $querycity2 = $db->execute("SELECT * FROM Cities Where $player->level >= Minimum_Level"); but earlier it was stated that it's not valid SQL. I'm new too this, if it's not valid, how is it pulling the right info? If anyone is not familiar with ezRPG, the pages use Adodb. $player is getting it's information from function.php . include("lib.php"); $player = check_user($secret_key, $db); Not sure if it helps, but here is a zip with both the drive.php and the function.php http://www.caraudiocentral.net/CAC_Mafia_Life/New%20Folder.zip
  6. This is a page I'm creating to work with EzRPG $player = check_user($secret_key, $db); which pulls the current player info from function.php This code here, works for pulling the correct cities $querycity2 = $db->execute("SELECT * FROM Cities Where $player->level >= Minimum_Level"); echo "<table width=\"100%\">\n"; echo "<tr class=\"cellheader\"><td><div align=\"center\">Wanna Go Somewhere do ya?</div></td></tr><tr>\n"; echo "<td><div align=\"center\">Here are the cities that you can go too.</div></td></tr><tr>\n"; echo "<td>\n"; while ($getcity2 = $querycity2->fetchrow()) echo $getcity2['City_Name'] . "<br />"; echo "</td>\n"; echo "</tr></table>\n"; ?> But I didn't know how to make each city be a link, that updates the City_ID field in the player table. That's where redarrow has been helping me, but I can't seem to get it to work. That's when I noticed his select is different from what I had. If anyone has any other suggestions on how to create a query that will pull the correct cities based on the players level, and then make it so they can click on a city, which will update their City_ID in their player table. Please respond.
  7. I tried to echo it out, and it actually displays '"SELECT * FROM Cities Where $player='level' >= 'Minimum_Level'";' on the screen. This is really weird, and I just don't understand it. If I use this select by itself $querycity2 = $db->execute("SELECT * FROM Cities Where $player->level >= Minimum_Level"); and echo it out, it gives me the correct cities from the cities table. But.. If I use that same select, in the code that you helped me with it doesn't give me the same results? but even with the cities it does list, if I click on them. It doesn't update the players city location. I know we have to be so close to making this work, it has to be something small that we aren't seeing.
  8. Here is my whole page as it is right now <?php /*************************************/ /* ezRPG script */ /* Written by Khashul */ /* http://code.google.com/p/ezrpg */ /* http://www.bbgamezone.com/ */ /*************************************/ include("lib.php"); define("PAGENAME", "Wanna Go Somewhere?"); $player = check_user($secret_key, $db); include("templates/private_header.php"); ?> <?php $querycity ="SELECT * FROM Cities Where $player='level' >= 'Minimum_Level'"; $result1=mysql_query($querycity) or die(mysql_error()); echo "<table width=\"100%\">\n"; echo "<tr class=\"cellheader\"><td><div align=\"center\">Wanna Go Somewhere do ya?</div></td></tr><tr>\n"; echo "<td><div align=\"center\">Here are the cities that you can go too.</div></td></tr><tr>\n"; echo "<td>\n"; while ($getcity =mysql_fetch_assoc($result1)){ echo "<a href='".$_SERVER['PHP_SELF']."?cmd=go&id=".$getcity['City_ID'].">".$getcity['City_Name']."</a><br>"; echo "</td>\n"; echo "</tr></table>\n"; if($_GET['cmd']=="go"){ $city_id=mysql_real_escape_string($_GET['City_Id']); $sql="UPDATE set City_ID='$City_ID' FROM players WHERE id='".$_GET['id']."'"; $sql_result=mysql_query($sql)or die (mysql_error()); echo " ".$getcity['City_Name']." Updated!"; exit; } } ?> <?php include("templates/private_footer.php"); ?> I noticed the select statement is different then what I originally came up with. How is the above different from this? $querycity = $db->execute("SELECT * FROM Cities Where $player->level >= Minimum_Level"); This will give me all criteria met rows in the cities table, but they are not links and don't do anything.
  9. This gives me this warning Unknown column 'Object' in 'where clause' What does that mean?
  10. I'm still getting this error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/caraudi/public_html/CAC_Mafia_Life/drive.php on line 25 Is there way to attach documents on this forum? I don't see an attach icon? I was going to attach my page, not sure if it would help but thought I would post it just to make sure.
  11. OK, Not sure where the [/url] came from. let's try again echo "<a href='".$_SERVER['PHP_SELF']."?cmd=go&id=".$getcity['City_ID'].">".$getcity['City_Name']."</a><br>";
  12. Ok, the last time it wouldn't display all the records, and also displayed all the HTML in the link it had to do with the A Href line. could it be the same issue this time? echo "<a href='".$_SERVER['PHP_SELF']."?cmd=go&id=".$getcity['City_ID'].">".$getcity['City_Name']."</a><br>"; Is there anything here I should fix?
  13. OK, I changed my select query a little to this $querycity = "SELECT * FROM Cities Where $player->level >= Minimum_Level"; and the error goes away, but it goes back to only displaying 1 record, and when I put my house over the hyperlink. I get this URL again it looks it has my HTML tags in it, I see TD, TR etc. http://www.caraudiocentral.net/CAC_Mafia_Life/drive.php?cmd=go&id=1%3ECAC%20Downtown%20District%3C/a%3E%3Cbr%3E%3C/td%3E%3C/tr%3E%3C/table%3E%3Ca%20href=
  14. I'm not really sure what that error means? Is there something wrong with this while ($getcity =mysql_fetch_assoc($result1)){ or is it not liking the query itself?
  15. I just gave it a try, and get this error mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource on line 25 Line 25 is this while ($getcity =mysql_fetch_assoc($result1)){
  16. Does anyone else have any suggestions? I'm stuck. I got it to display both rows again like it's suppose too. But now not sure how to make it actually update the players location? I'm pretty sure I need a $players->City_ID or some variable in the update to make only that players location?
  17. hmm, Something else I just realized, I haven't told it to only update the currently logged in player. Shouldn't I have a $player->City_ID somewhere in the update query? or something like that? Like I did in the select query?
  18. I messed with it some more, and if I change the <a href line to this echo "<a href='#?cmd=go&id={$getcity['City_ID']}'>{$getcity['City_Name']}</a><br>"; It will go back to displaying both rows in the table, like it should. When I move my house over the link, it gives me a URL like this. drive.php#?cmd=go&id=1 Does this look right so far? I'm still unclear what to put down as a link? It's really not going to another page, I just want the links to update the field and then display the message 'you've traveled to 'name of city' Right now when I click on the link, it's not doing anything. It doesn't update the field, and it's not displaying the message. So I'm guessing that there is something not right here? if($_GET['cmd']=="go") { $sql="UPDATE set City_ID='$City_ID' FROM players WHERE id='".$getcity['City_Id']."'"; $sql_result=mysql_query($sql)or die (mysql_error()); echo " ".$getcity['City_Name']." Updated!"; Here is my entire code <?php $querycity = $db->execute("SELECT * FROM Cities Where $player->level >= Minimum_Level"); echo "<table width=\"100%\">\n"; echo "<tr class=\"cellheader\"><td><div align=\"center\">Wanna Go Somewhere do ya?</div></td></tr><tr>\n"; echo "<td><div align=\"center\">Here are the cities that you can go too.</div></td></tr><tr>\n"; echo "<td>\n"; while ($getcity = $querycity->fetchrow()){ echo "<a href='#?cmd=go&id={$getcity['City_ID']}'>{$getcity['City_Name']}</a><br>"; echo "</td>\n"; echo "</tr></table>\n"; if($_GET['cmd']=="go") { $sql="UPDATE set City_ID='$City_ID' FROM players WHERE id='".$getcity['City_Id']."'"; $sql_result=mysql_query($sql)or die (mysql_error()); echo " ".$getcity['City_Name']." Updated!"; } } ?>
  19. That worked great!! Thank You
  20. Hi, I have a update query, that is run with a cron every 15 minutes. $query = $db->execute("update `players` set hp = hp + 10" ); What it does is increases a players hp 10 every 15 minutes. this part is working good, but here is the problem. Depending on the level a player is, they have a maxhp (there is a field name in the players table called maxhp) How can I make it so it updates up to the maxhp and then stop? Right now, it just keeps going and going and going (lol)
  21. I've been playing with this some more, and just can't get it to work. does the code I posted above look right? I just can't figure out why it's only displaying 1 city now, and then the link it displays doesn't seem to be right.
  22. It doesn't seem to be working and I'm not sure why. Here is what I have <?php $querycity = $db->execute("SELECT * FROM Cities Where $player->level >= Minimum_Level"); echo "<table width=\"100%\">\n"; echo "<tr class=\"cellheader\"><td><div align=\"center\">Wanna Go Somewhere do ya?</div></td></tr><tr>\n"; echo "<td><div align=\"center\">Here are the cities that you can go too.</div></td></tr><tr>\n"; echo "<td>\n"; while ($getcity = $querycity->fetchrow()){ echo "<a href='drive.php?cmd=go&id=".$getcity['City_Id']." > ".$getcity['City_Name']. "</a> <br>"; echo "</td>\n"; echo "</tr></table>\n"; if($_GET['cmd']=="go"){ $sql="UPDATE set City_ID='$City_ID' FROM Players WHERE id='".$getcity['City_Id']."'"; $sql_result=mysql_query($sql)or die (mysql_error()); echo " ".$getcity['City_Name']." Updated!"; } } ?> right now, it's only listing out the first row in my cities table. Where before it would list out the 2 cities I have in the db. But your select query looks almost the same as mine. So not sure why it's not pulling both, like it was before. but the link it does show, doesn't want to update the City_ID field within my Players table. (sorry I just noticed I said level field in my first post, I was thinking of something else, and just typed level). The URL it points to is odd too, is this is how it should look? /CAC_Mafia_Life/drive.php?cmd=go&id=%20%3E%20CAC%20Downtown%20District%3C/a%3E%20%3Cbr%3E%3Ca%20href= What I don't under stand is, the link it displays is 'SEattle' which is the first row in my DB CAC Downtown District is the name of the city in the second row? This line echo "<a href='drive.php?cmd=go&id=".$getcity['City_Id']." > ".$getcity['City_Name']. "</a> <br>"; What page should I reference there? the page I'm putting this code is drive.php, so I should put drive.php there right? I'm also not sure what $City_ID is? It's a variable right? But where is this line pulling that from? $sql="UPDATE set City_ID='$City_ID' FROM Players WHERE id='".$getcity['City_Id']."'"; I have a feeling I'm just misinterpreting what fields are which, and once I fix it, this will work.
  23. Cool Thanks! I was just working on the update part, thank you for doing that for me. My version wasn't quite like that, so I'm sure it would have caused an error I just tried it, and for some reason it's not displaying the cities anymore. I'm not sure why tho, it looks like it should..
  24. Hi, I'm not sure if this should go in the php forum of the mysql forum. Hope this is the right place. I'm trying to create a page, that displays the cities a player can go to. What I want to do is have the name of the city be a hyperlink. When the link is clicked it updates the 'level' field in the 'players' table. Then display a message saying you've traveled to 'whatever city they clicked on' here is what I have so far, which displays the proper cities for a player depending on their level. The problem I'm having is, I'm not sure how to make it so city names are links, that update the table. <?php $querycity = $db->execute("SELECT * FROM Cities Where $player->level >= Minimum_Level"); echo "<table width=\"100%\">\n"; echo "<tr class=\"cellheader\"><td><div align=\"center\">Wanna Go Somewhere do ya?</div></td></tr><tr>\n"; echo "<td><div align=\"center\">Here are the cities that you can go too.</div></td></tr><tr>\n"; echo "<td>\n"; while ($getcity = $querycity->fetchrow()) echo $getcity['City_Name'] . "<br />"; echo "</td>\n"; echo "</tr></table>\n"; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.