Jump to content

Archived

This topic is now archived and is closed to further replies.

unklematt

Creating links from a list

Recommended Posts

I have a question to ask -- as normal...

I have a row of pages in a list ie:

[code]

link1,link2,link3,link4

[/code]

which are written to my database just using a $link variable

How do I get them to be like

[code]

<a href='http://link1'>link1</a>'
<a href='http://link2'>link2</a>'
<a href='http://link3'>link3</a>'
<a href='http://link4'>link4</a>'
[/code]

I know how to do the str_replace etc but the getting them link is doing my head in LOL[quote]

Share this post


Link to post
Share on other sites
If you are storing them in a database, like you say, this should work fine...
[code]<?php
$result = mysql_query("SELECT `link` FROM `table`") or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
    echo "<a href='http://$row[link]'>$row[link]</a><br/>";
}
?>[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=351923:date=Mar 5 2006, 06:12 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Mar 5 2006, 06:12 PM) [snapback]351923[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If you are storing them in a database, like you say, this should work fine...
[code]<?php
$result = mysql_query("SELECT `link` FROM `table`") or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
    echo "<a href='http://$row[link]'>$row[link]</a><br/>";
}
?>[/code]
[/quote]

That just seems to bring it out as one link

[code]
http://link1,link2,link3,link4
[/code]


here is the chunk of code I am using..
[code]
echo "<tr><td>Link:</td><td>";
$name=$row['name'];
$result1 = mysql_query("SELECT `link` FROM `myjunk`where name like '$name'") or die(mysql_error());
while($row = mysql_fetch_assoc($result1)) {
echo "<a href='links/$row[link]'>$row[link]</a><br/>";
}
echo"</td></tr>";
}
[/code]

Share this post


Link to post
Share on other sites
Do you mean that you have [b]one field[/b] in each [b]row[/b] of your database that looks like url1,url2,url3 (all joined up but separated with commas)? If that's so you you need to retrieve the field and then use the explode() function on the comma separator to generate an array of links ...

Share this post


Link to post
Share on other sites
[!--quoteo(post=351943:date=Mar 5 2006, 07:58 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Mar 5 2006, 07:58 PM) [snapback]351943[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Do you mean that you have [b]one field[/b] in each [b]row[/b] of your database that looks like url1,url2,url3 (all joined up but separated with commas)? If that's so you you need to retrieve the field and then use the explode() function on the comma separator to generate an array of links ...
[/quote]

Excellent thank you... worked a treat.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.