Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic links

Status
Not open for further replies.

secretsquirrel

Programmer
Mar 22, 2001
202
GB
hi,

i've got a mysql table containing a set of text articles and the title of the article.

i've written some code which generates an html table containing a list of the titles, and i need these titles to link the article it relates to.

i'm thinking i can do this by setting each link to point to the same page (eg. 'showArticle.php'), but passing a variable to that page so it knows which article to retrieve and display.

i managed to get as far as <a href="">$title</a> but wasn't sure where to go from there!

can anyone suggest how i could achieve this? presumably i would need to pass 'showArticle.php' the article ID from the table, but i'm not sure how to.

i can post some code if it'll be helpful.

thanks in advance,

ss...
 
Retrieve the entire row from the MySQL table:
Code:
$row = mysql_fetch_assoc($result);
Then you have all columns available to populate the required HTML parameters:
Code:
echo('<a href="/path/showarticle.php?id='.$row['id'].'">'.$row['title']."</a>\n");

That's it.
 
i thought it'd be something like that, but wasn't sure.

does this method mean that showArticle.php would now have a variable called $id containing the row number?

that might sound like a dumb question, but it's not something i've ever had to do before.

thanks,

ss...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top