Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Adding Html link to every line of database

New Here ,
Jun 11, 2009 Jun 11, 2009

I know the heading sounded a bit strange so I will try to explain it here:

I have created a recordset of a database which lists the top sites of the day now the database has a field site_names in which I add the top ten site names every day.

I m already using the nl2br code to add a line break after every line.

Now I want the lines to link to their respective sites.

See if we try to create a click here link that links to http://www.adobe.com then the code generated will be like this:

                         <a href="http://www.adobe.com">Click Here</a>

Now lets say the sites that I have added are

     http://www.blogator.blogspot.com

     http://www.tensports.com

     http://www.fifa.com

so I need a code such that these values get converted into not in the database but only in the browser.

     <a href="http://www.blogator.blogspot.com">http://www.blogator.blogspot.com</a>

     <a href=" http://www.tensports.com"> http://www.tensports.com</a>

     <a href=" http://www.fifa.com">http://www.fifa.com</a>

plz help the code that I m using now is this

     <?php echo nl2br ($row_rsSites['site_names']); ?>

this code allows to add a line break to all the lines in a database.

Plz help if any one of you have not understood what m trying to explain plz let me know I will try to explain again.

TOPICS
Server side applications
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 11, 2009 Jun 11, 2009

<a href="<?php echo ($row_rsSites['site_names']); ?>"><?php echo ($row_rsSites['site_names']); ?></a><br>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 11, 2009 Jun 11, 2009

Ya I tried that man the problem is that all the 10 links are presents in one databse feild like this

    http://www.blogator.blogspot.com

    http://www.tensports.com

    http://www.fifa.com

and applying the code that you gave the result comes out to be this

    http://www.blogater.blogspot.comhttp://www.tensports.comhttp://www.fifa.com

try to hover on the line and see the address it links too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 11, 2009 Jun 11, 2009

Looks like it's time to change your database field.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 11, 2009 Jun 11, 2009

Are those all the site names in one row or different rows in table?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2009 Jun 12, 2009

They are in one row actually there are 10 links in one row I have just showed 3.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 12, 2009 Jun 12, 2009

I'm not pretty sure how you store all the site names in one row. Are u using some function? What function is that (implode,join)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2009 Jun 12, 2009

no I m not into php and mysql so much and I don't even know whats implode join is I just go to php myadmin and add the data

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 12, 2009 Jun 12, 2009

Owh, no no... If u do like no matter what it will show only one row too in ur page although u add <br> as in post previously. What server side language did u use (PHP, ASP,etc)? Other option is u have to add all the site names in different rows of table so they can be arranged separately. Could u please post here that table structure in database?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2009 Jun 12, 2009

Well PHP is what m using

and ya I know that the content of a row comes in one line thats why I have used nl2br tag in the code

     <?php echo nl2br ($row_rsSites['site_names']); ?>

nl2br ads a br tag to each line in a databse so what I want is a code that not only lists the content of the database in to a new line but also add a link respective to the line well applying the above code gives this result

     http://www.blogator.blogspot.com

     http://www.tensports.com

     http://www.fifa.com

but they just don't link to their respective sites as u can see here.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2009 Jun 12, 2009

Ok let me simplify it when I type a website address in adobe like I m now it comes out to be like this

     http://www.wwe.com

But when I add this same line to a post it comes out with out any links in my site

     http://www.wwe.com
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 12, 2009 Jun 12, 2009

As the others have said, maybe time to reconsider your database structure. However, since each URL is separated by a newline character, what you want to do is fairly easy.

$sites = explode("\n", $row_rsSites['site_names']);

foreach ($sites as $site) {

  echo "<a href='$site'>$site</a><br />";

}

The first line creates an array of the sites, breaking them at the new line character. The rest of the code uses a foreach loop to go through each URL in the array, and uses echo to create the link.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2009 Jun 12, 2009

Thanks Man it works great Thanks a lot.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 13, 2009 Jun 13, 2009
LATEST

Marking this thread as "assumed answered".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines