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

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-04-2003
Acorn Tutors
 
Posts: n/a
Default 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>



Reply With Quote
  #2 (permalink)  
Old 10-04-2003
Pedro
 
Posts: n/a
Default Re: How do you take a db table entry and make it into a link?

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.
Reply With Quote
  #3 (permalink)  
Old 10-05-2003
Nikolai Chuvakhin
 
Posts: n/a
Default Re: How do you take a db table entry and make it into a link?

"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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:44 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0