Copy link to clipboard
Copied
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
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.
Copy link to clipboard
Copied
<a href="<?php echo ($row_rsSites['site_names']); ?>"><?php echo ($row_rsSites['site_names']); ?></a><br>
Copy link to clipboard
Copied
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
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.
Copy link to clipboard
Copied
Looks like it's time to change your database field.
Copy link to clipboard
Copied
Are those all the site names in one row or different rows in table?
Copy link to clipboard
Copied
They are in one row actually there are 10 links in one row I have just showed 3.
Copy link to clipboard
Copied
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)?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
but they just don't link to their respective sites as u can see here.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks Man it works great Thanks a lot.
Copy link to clipboard
Copied
Marking this thread as "assumed answered".