This is a discussion on How do you take a db table entry and make it into a link? within the PHP Language forums, part of the PHP Programming Forums category; Hi folks, what I would like to do is to store the name of a link, such as link1.php ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi folks, what I would like to do is to store the name of a link, such as
link1.php in a field, lets say the field is called Favoritelinks, in a database as a bit of text. Then, on a logged in page, pull the value from the field and put in right in the <a href><a> tag so that the link now points to a file, and is dynamic. And, depending on the username and password, the value taken from Favoritelinks changes. What Im after is to provide a link from a field (in this case Favoritelinks). The entry in the field is simple text such as "link1.php". Then, in a logged in file, use this text to create a link. Now, as to which row is accessed to provide the actual text from the Favoritelinks field, that depends on matching a username and password from two other fields in the same table. So, for example username bill, password test1 will have the entry link1.php in his Favoritelinks field. username frank, password test2 will have the entry link2.php in his Favoritelinks field. I would like to have the logged in screen change so that the hypertext link will point to link1.php in the link for bill if he logs in and for it to then be link2.php if frank logs in. So if bill logs in the html will show <a href: link1.php>Click here<a> and if frank logs in, it will show <a href: link2.php>Click here<a> |
|
|||
|
Acorn Tutors wrote:
> So if bill logs in the html will show <a href: link1.php>Click here<a> > > and if frank logs in, it will show <a href: link2.php>Click here<a> Your HTML is wrong: it should be <a href="link1.php">Click here</a> _______^_______________________^__ After you get the text from the database simply echo it! <a href="<?php echo $dbdata['FavouriteLink']; ?>">Click here</a> -- I have a spam filter working. To mail me include "urkxvq" (with or without the quotes) in the subject line, or your mail will be ruthlessly discarded. |
|
|||
|
"Acorn Tutors" <info@acorntutors.com> wrote in message
news:<TtEfb.6464$Tu2.886007@news20.bellglobal.com> ... > > what I would like to do is to store the name of a link, such as > link1.php in a field, lets say the field is called Favoritelinks, > in a database as a bit of text. Then, on a logged in page, pull > the value from the field and put in right in the <a href><a> tag > so that the link now points to a file, and is dynamic. And, > depending on the username and password, the value taken from > Favoritelinks changes. OK, let's say your users store their favorite links in a table called `links`, which has a bunch of fields including these: user_id (the ID of the user to whom the link belongs) URL (the URL to the resource) description (the description of the resource) So here is what you need to do to display links that belong to the user whose ID is, say, 123: mysql_connect ('host', 'user', 'password') or die ('Could not connect: ' . mysql_error ()); mysql_select_db ('mydb') or die ('Could not select database'); $query = 'SELECT URL, description FROM links WHERE user_id=123'; $result = mysql_query ($query) or die ('Query failed: ' . mysql_error ()); echo "<ul>\n"; while ($link = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<li><a href="', $link['URL'], '">', $link['description'], "</a>\n"; } echo "</ul>\n"; Cheers, NC |