468,290 Members | 1,895 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

How do you take a db table entry and make it into a link?

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>

Jul 17 '05 #1
2 1912
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.
Jul 17 '05 #2
"Acorn Tutors" <in**@acorntutors.com> wrote in message
news:<Tt*******************@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
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by john_williams_800 | last post: by
1 post views Thread by Mats Kling | last post: by
21 posts views Thread by Johan Tibell | last post: by
reply views Thread by elainenguyen | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.