Demonicman
01-06-2015, 05:11 AM
Ok so I have a table like so:
Name---------Bank----------Store----------Library
Town1---------1,6---------15,2---------12,16
Town2---------3,2---------2,8---------16,16
So my question is how do I get the name of the column for use in a variable?
This is for a map. So when the map builds on the screen for the player, I will put the current user coordinates into a string to find a match on the table and fetch the column that it is in. So if the user is in Town1 and they are on the coordinates 15,2 then they should be able to see a picture of a Store. If I use the town Name in the query, I would have to check each column in a loop to match the correct coordinates to the correct column name to determine what should be on that location, and I fear that would be hard on the server to constantly do that every single time someone moves locations on the map.
In the most simplest sense, I want to be able to fetch the column name based on the if the coordinates are in that column. That way I can just put the column name into a variable string to be used in both a link and a different picture than the rest of the map.
///// First check current user location with a query to the Users table and put into a fetch array variable called $User.
$User=mysqli_fetch_array(mysqli_query("select * from Users where ID='1'"));
echo "You are at $User[Town] at the coordinates $User[Coords]";
///// Find column name in town table where $User[Town] matches the row and then find what column the matching $User[Coords] is in to put in a variable called $Name
echo "Here is the store: <a href='$Name.php'><img src='$Name.jpg'></a>";
Name---------Bank----------Store----------Library
Town1---------1,6---------15,2---------12,16
Town2---------3,2---------2,8---------16,16
So my question is how do I get the name of the column for use in a variable?
This is for a map. So when the map builds on the screen for the player, I will put the current user coordinates into a string to find a match on the table and fetch the column that it is in. So if the user is in Town1 and they are on the coordinates 15,2 then they should be able to see a picture of a Store. If I use the town Name in the query, I would have to check each column in a loop to match the correct coordinates to the correct column name to determine what should be on that location, and I fear that would be hard on the server to constantly do that every single time someone moves locations on the map.
In the most simplest sense, I want to be able to fetch the column name based on the if the coordinates are in that column. That way I can just put the column name into a variable string to be used in both a link and a different picture than the rest of the map.
///// First check current user location with a query to the Users table and put into a fetch array variable called $User.
$User=mysqli_fetch_array(mysqli_query("select * from Users where ID='1'"));
echo "You are at $User[Town] at the coordinates $User[Coords]";
///// Find column name in town table where $User[Town] matches the row and then find what column the matching $User[Coords] is in to put in a variable called $Name
echo "Here is the store: <a href='$Name.php'><img src='$Name.jpg'></a>";