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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.