cdoyle Posted March 17, 2008 Share Posted March 17, 2008 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"; ?> Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/ Share on other sites More sharing options...
redarrow Posted March 17, 2008 Share Posted March 17, 2008 example only... <?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='page.php?cmd=go&id=".$getcity['city_id']."> ".$getcity['City_Name']. "</a> <br>"; echo "</td>\n"; echo "</tr></table>\n"; if($_GET['cmd']=="go"){ //update the database. where id='."getcity['city_id'] } ?> Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-493695 Share on other sites More sharing options...
redarrow Posted March 17, 2008 Share Posted March 17, 2008 re vamped code sorry trie this.......... remember to use the id name in the database as i guessed......... <?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='page.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 level='$level' FROM cities WHERE id='".$getcity['City_Id']."'"; $sql_result=mysql_query($sql)or die (mysql_error()); echo " ".$getcity['City_name']." Updated!"; } ?> Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-493702 Share on other sites More sharing options...
cdoyle Posted March 17, 2008 Author Share Posted March 17, 2008 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.. Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-493713 Share on other sites More sharing options...
redarrow Posted March 17, 2008 Share Posted March 17, 2008 try this mate no good at class sorry... all i done is add a loop brace while ($getcity = $querycity->fetchrow()){ cheek my spelling sorry... <?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='page.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 level='$level' FROM cities WHERE id='".$getcity['City_Id']."'"; $sql_result=mysql_query($sql)or die (mysql_error()); echo " ".$getcity['City_name']." Updated!"; } } ?> Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-493715 Share on other sites More sharing options...
cdoyle Posted March 17, 2008 Author Share Posted March 17, 2008 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. Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-493771 Share on other sites More sharing options...
cdoyle Posted March 17, 2008 Author Share Posted March 17, 2008 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. Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-494073 Share on other sites More sharing options...
cdoyle Posted March 17, 2008 Author Share Posted March 17, 2008 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!"; } } ?> Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-494487 Share on other sites More sharing options...
cdoyle Posted March 18, 2008 Author Share Posted March 18, 2008 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? Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-494491 Share on other sites More sharing options...
cdoyle Posted March 18, 2008 Author Share Posted March 18, 2008 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? Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-494974 Share on other sites More sharing options...
redarrow Posted March 20, 2008 Share Posted March 20, 2008 try this please cheers............. <?php $querycity ="SELECT * FROM Cities Where $player='level' >= 'Minimum_Level'"; $result1=mysql_query($querycity); 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=$_POST['City_Id']; $city_id=mysql_real_escape_string(($getcity['City_Id'])); $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!"; } } ?> Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-496587 Share on other sites More sharing options...
cdoyle Posted March 20, 2008 Author Share Posted March 20, 2008 try this please cheers............. <?php $querycity ="SELECT * FROM Cities Where $player='level' >= 'Minimum_Level'"; $result1=mysql_query($querycity); 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=$_POST['City_Id']; $city_id=mysql_real_escape_string(($getcity['City_Id'])); $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!"; } } ?> 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)){ Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-496682 Share on other sites More sharing options...
cdoyle Posted March 20, 2008 Author Share Posted March 20, 2008 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? Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-497083 Share on other sites More sharing options...
cdoyle Posted March 20, 2008 Author Share Posted March 20, 2008 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= Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-497109 Share on other sites More sharing options...
cdoyle Posted March 21, 2008 Author Share Posted March 21, 2008 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? Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-497309 Share on other sites More sharing options...
cdoyle Posted March 21, 2008 Author Share Posted March 21, 2008 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>"; Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-497310 Share on other sites More sharing options...
redarrow Posted March 21, 2008 Share Posted March 21, 2008 anyone why this wrong did i write the code wrong tell me user needs help cheers... the page should update accoring to url........ <?php $querycity ="SELECT * FROM Cities Where $player='level' >= 'Minimum_Level'"; $result1=mysql_query($querycity); 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=$_POST['City_Id']; $city_id=mysql_real_escape_string(($getcity['City_Id'])); $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!"; } } ?> Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-497825 Share on other sites More sharing options...
redarrow Posted March 21, 2008 Share Posted March 21, 2008 all i can think off <?php $querycity ="SELECT * FROM Cities Where $player='level' >= 'Minimum_Level'"; $result1=mysql_query($querycity); 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; } } ?> Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-497832 Share on other sites More sharing options...
cdoyle Posted March 21, 2008 Author Share Posted March 21, 2008 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. Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-497881 Share on other sites More sharing options...
BlueSkyIS Posted March 21, 2008 Share Posted March 21, 2008 change this $result1=mysql_query($querycity); to this: $result1=mysql_query($querycity) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-497890 Share on other sites More sharing options...
cdoyle Posted March 22, 2008 Author Share Posted March 22, 2008 change this $result1=mysql_query($querycity); to this: $result1=mysql_query($querycity) or die(mysql_error()); This gives me this warning Unknown column 'Object' in 'where clause' What does that mean? Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-498054 Share on other sites More sharing options...
cdoyle Posted March 22, 2008 Author Share Posted March 22, 2008 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. Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-498055 Share on other sites More sharing options...
redarrow Posted March 22, 2008 Share Posted March 22, 2008 this can not be right then $querycity ="SELECT * FROM Cities Where $player='level' >= 'Minimum_Level'"; echo it out see if it correct Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-498180 Share on other sites More sharing options...
cdoyle Posted March 22, 2008 Author Share Posted March 22, 2008 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. Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-498216 Share on other sites More sharing options...
BlueSkyIS Posted March 22, 2008 Share Posted March 22, 2008 as far as i know, neither of these is valid SQL (and they are not the same, either way): SELECT * FROM Cities Where $player='level' >= 'Minimum_Level' SELECT * FROM Cities Where $player->level >= Minimum_Level what is $player='level' or $player->level supposed to be? Link to comment https://forums.phpfreaks.com/topic/96466-help-with-creating-hyperlink/#findComment-498219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.