Jump to content

Creating links from a list


unklematt

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]
Link to comment
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]
Link to comment
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]
Link to comment
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 ...
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.