SamNewbie Posted April 8, 2014 Share Posted April 8, 2014 Hey, I have got the results displayed from the database when it gets the ID in the URL but I am having a problem with one the results, in lists.php, there is a list of cities as an array city=array(0=>"London") But in the results, it is displaying the '1' instead of 'London', i need it to display 'London'. Below is my coding... it is all connected to the database. How do i change the data type? <?php if (isset($_GET['id'])){ $query="SELECT*FROM user WHERE user_id=".$_GET['id']; $results = mysql_query($query) or die (mysql_error()); while($row = mysql_fetch_array($results)){ echo "Name: ".$row['user_firstname']." ".$row['user_surname']; echo "<br /><br />"; echo "Date of Birth: ".$row['user_dob']; echo "<br /><br />"; echo "Gender: ".$row['user_gender']; echo "<br /><br />"; echo "City: ",$row['user_city']; echo "<br /><br />"; } } Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/287615-how-to-change-one-of-the-results-to-a-string/ Share on other sites More sharing options...
Ch0cu3r Posted April 8, 2014 Share Posted April 8, 2014 (edited) Your mean $row['user_city'] returns 1 and not London? The user_city field in the users table may be used as a foreign key to retrieve the actual city name from another table in your database? Edited April 8, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/287615-how-to-change-one-of-the-results-to-a-string/#findComment-1475409 Share on other sites More sharing options...
SamNewbie Posted April 8, 2014 Author Share Posted April 8, 2014 Your mean $row['user_city'] returns 1 and not London? The user_city field in the users table may be used as a foreign key to retrieve the actual city name from another table in your database? Hi Ch0cu3r, Yes, user_city and gender are listed as numbers. For this project, I cannot change the data within the database and the two entities have to be kept as numerical format. Is there anyway to make gender (currently 1 is male and 2 is female), display as male and female respectively? Is there a way to do this with city names as well? Currently 1 = Aberdeen, 2 = London etc... Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/287615-how-to-change-one-of-the-results-to-a-string/#findComment-1475411 Share on other sites More sharing options...
Ch0cu3r Posted April 8, 2014 Share Posted April 8, 2014 Yes, you'll need to use JOINS in your query to fetch the data from the other tables, example Can you post a the schema for the gender and city tables? For this project, I cannot change the data within the database and the two entities have to be kept as numerical format. That is good practice, it called data normalisation. Quote Link to comment https://forums.phpfreaks.com/topic/287615-how-to-change-one-of-the-results-to-a-string/#findComment-1475414 Share on other sites More sharing options...
SamNewbie Posted April 8, 2014 Author Share Posted April 8, 2014 (edited) m Edited April 8, 2014 by SamNewbie Quote Link to comment https://forums.phpfreaks.com/topic/287615-how-to-change-one-of-the-results-to-a-string/#findComment-1475415 Share on other sites More sharing options...
Ch0cu3r Posted April 8, 2014 Share Posted April 8, 2014 (edited) You never said that before, so the cities are listed in a $citenames array and the same applies for gender? In that case you need to first include lists.php include 'lists.php'; and the use $row['user_city'] as the array index for the $citynames array, eg echo "City: ", $citynames[ $row['user_city'] ]; If the genders is also listed in lists.php then you'll do a similar thing for gender echo "Gender: ". $gender_array_var[ $row['user_gender'] ]; Change $gender_array to the name of the variable that holds the array of genders Edited April 8, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/287615-how-to-change-one-of-the-results-to-a-string/#findComment-1475417 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.