Jump to content

MySQL Query from DB -> Hyperlink to show record


Recommended Posts

Hi. I'm fairly new to PHP/MySQL so bare with me!

 

I have a database in place with team names and players in. Each record has an auto-incrementing ID, a team name, and 5 player names. I have selected all the information from the table and have displayed the team names in a while loop, so it ticks through and displays them all ($row['Team_Name'];).

 

Basically, what I can't work out to do is how to make the team names hyperlinks, so that clicking on them goes to a new page where it lists their players. I tried <a href = "$row['Team_Name']"> . $row['Team_Name']; . <?a>, but I think it's a bit more complex than that as that doesn't work!

 

Sorry if some of my syntaxing above is wrong - I'm on a college computer and my code is on my laptop so some stuff above is wrong, but I dare say you'll know exactly what I mean!

 

Thanks.

It's pretty easy, you just have to make a new php script to link to.

For example the page that displays the list of teams might be index.php

And the one that displays the team players might be team.php

That way you can link like

echo '<a href = "team.php?team='.$row['Team_Name'].'"> . $row['Team_Name'] . </a>

That way the team name is passed to the team.php script via the get method, (notice the ?team= at the end)

Then in the next page you can select the row that has that teams details.

use this: http://pastebin.com/N8iUViEj as an example.

I have to go so I can't write the whole thing for you.

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.