jdar Posted August 18, 2010 Share Posted August 18, 2010 Hello, I have a quick question about methods for retrieving records from a mysql table and displaying them as a links For example, imagine I have three tables called countries, cities and city_info. I'd like to be able to select a country and have a list of that country's city names returned as links. I'd then like to be able to click on the link for London, say, and that would trigger a mysql query to retrieve the entry in city_info about London. Are there any functions that allow this? If anyone could point me in the right direction for further research I'd be grateful. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/211064-displaying-mysql-results-as-urlslinks/ Share on other sites More sharing options...
phpology Posted August 18, 2010 Share Posted August 18, 2010 You would need to go through your recordset and write the links yourself when you are looping: while($result = mysql_fetch_array($recordset)) { echo "<a href=\"cities.php?country_id=".$result['id']."\">".$result['country_name']."</a>\n"; } when cities.php is opened you then run another query to get the list of cities based on that country id. You could do it all inline i.e. without jumping to another php page using jquery/ajax but that is your call. or what you can do is create a 3d array where you combine all your results in one array but I am guessing there is going to be loads of data so this method might not be that useful. Quote Link to comment https://forums.phpfreaks.com/topic/211064-displaying-mysql-results-as-urlslinks/#findComment-1100778 Share on other sites More sharing options...
jdar Posted August 20, 2010 Author Share Posted August 20, 2010 Hi, thanks a lot for your advice. I haven't got around to testing it yet, but it looks promising. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/211064-displaying-mysql-results-as-urlslinks/#findComment-1101784 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.