Jump to content

Displaying mysql results as urls/links?


jdar

Recommended Posts

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. 

Link to comment
https://forums.phpfreaks.com/topic/211064-displaying-mysql-results-as-urlslinks/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.