Current location: Hot Scripts Forums » Programming Languages » PHP » Adding a Hyper Link to a Text statement in PHP


Adding a Hyper Link to a Text statement in PHP

Reply
  #1 (permalink)  
Old 04-07-06, 03:38 PM
kpowers4 kpowers4 is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Adding a Hyper Link to a Text statement in PHP

I need help adding Hyper Links to my PHP (array generated) short text descriptions. Id like the link to reference a file that has a long text description, the hyper link should open up another window.

Any help or tips would be helpfull!!

Here is the php code that displays the descriptions (text) from my MySQL database:


PHP Code:
PHP Code:

 for($i=$n_start;$i<=$n_end;$i++) 

 {  
    echo 
"<tr>"
    echo 
"<td align='center'> 
                 
{$products[$i]['catalog_number']}</td>\n"
    echo 
"<td>{$products[$i]['description']}</td>\n"
    echo 
"<td>\${$products[$i]['price']} </td>\n"
    echo 
"<td><img src='images/{$products[$i]['pix']}'></td> \n";  
    echo 
"</tr>"
 } 

Last edited by Christian; 04-07-06 at 03:40 PM. Reason: Please use [PHP][/PHP] when posting php code!
Reply With Quote
  #2 (permalink)  
Old 04-07-06, 05:01 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
If you literally want this long description to be contained in a file, there are two ways to add a link.

The 1st way, a field with a file name is added to your database for each product, something like - $products[$i]['longdescription'] This can then be used to form the link.

The 2nd way, if you cannot or don't want to modify your database tables, would be to use the $products[$i]['catalog_number'] to form the file name in the link. This assumes that your catalog numbers can all be used as file names.

For the 1st way, the complete file name with a .txt or .html extension (or whatever you want) would be stored in the database. For the 2nd way, a .txt or .html would need to be added to the catalog number part to form the file name.

In ether case, the existing short description in the table would be changed. You can either change it entirely into a link or add a link to part of it.

To change the entire short description into a link -
PHP Code:

echo "<td><a target='_blank' href='what file to open goes here'>{$products[$i]['description']}</a></td>\n"
To add something like "more info..." as a link onto the end of the short description -
PHP Code:

echo "<td>{$products[$i]['description']}<a target='_blank' href='what file to open goes here'>more info...</a></td>\n"
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #3 (permalink)  
Old 04-07-06, 11:48 PM
kpowers4 kpowers4 is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Hey thanks again!! You gave me a great solution. I stuck with option #1 and added the link (to the text) in my database. Then i just echo it back out with the line of text. The code for anyone else looks like this:

PHP Code:
echo "<td><a target='_blank' href={$products[$i]['link']}>{$products[$i]['description']}</a></td>\n";
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 04:03 AM
Six Sites Exchanging Links! - PR3+ Web Hosting, Web Design, Entertainment & Career coffeecoder General Advertisements 0 10-10-05 12:52 AM
PHP Link Crackboy PHP 1 03-09-05 11:04 AM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM
text file to link rush989 Script Requests 3 08-29-03 06:12 PM


All times are GMT -5. The time now is 07:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.