Need help creating links from table data.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Need help creating links from table data.

Post by cdoyle »

Hi

I have a 1 table in my database called cities, and another table in my database called players.
Here are the fields needed for this

Table Cities
City_ID
City_Name
City_Description
Minimum_Level

In the players table
id
username
level
City_ID

Here is what I'm trying to do.
I want to give my users the ability to travel from city to city within the game. When they go to the drive.php, it looks at their level and then pulls from the city table any city they meet the minimum level requirement (I have this part working)

I want the names of the cities to be a link, that they can click on. When clicked it updates the City_ID to the location in the players table to the location they clicked on.

Here is the code I have so far, it displays the proper cities, but I don't know how to make the links update this players City_ID.

Code: Select all

 
<?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!";
}
}
?>
 
When you move your cursor over the link, it shows an URL like this
http://www.caraudiocentral.net/CAC_Mafi ... md=go&id=1

Now if I can somehow update City_ID in the players table with that '1', I think this will work great.

I'm also thinking I'm missing in my update query, to tell it which player to update?
I should have a $players->City_ID or some type of variable in there right? Just like I did in the select query?
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Re: Need help creating links from table data.

Post by cdoyle »

Anyone have any suggestions?
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Re: Need help creating links from table data.

Post by cdoyle »

I'm still stuck on this, and if anyone has any suggestions please post :)

I went back to the beginning with this.

This code will display the proper cities depending on the players level. This part works, what I need to do next is have it so the city names are links they can click. When clicked, it will update the City_ID of the players table to the number of the city they clicked on.

Code: Select all

<?php
$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";
 
?>
<?php
 
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Re: Need help creating links from table data.

Post by cdoyle »

Here is the latest that I have

Code: Select all

 
<?php
 
$querycity2 = $db->execute("SELECT * FROM Cities Where $player->level >= Minimum_Level");
 
 
while ($getcity2 = $querycity2->fetchrow())
echo "<a href='#?act=go&id={$getcity2['City_ID']}'>{$getcity2['City_Name']}</a><br>";
 
 
?>
 
This makes the cities names links, but now I'm not sure how to make them so when clicked. It updates the City_ID within the players table?
Post Reply