unklematt Posted March 5, 2006 Share Posted March 5, 2006 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 variableHow 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] Quote Link to comment Share on other sites More sharing options...
zq29 Posted March 5, 2006 Share Posted March 5, 2006 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 Link to comment Share on other sites More sharing options...
unklematt Posted March 5, 2006 Author Share Posted March 5, 2006 [!--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] Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 6, 2006 Share Posted March 6, 2006 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 Link to comment Share on other sites More sharing options...
unklematt Posted March 6, 2006 Author Share Posted March 6, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
wickning1 Posted March 6, 2006 Share Posted March 6, 2006 Comma separated data is bad database design. Just so you know. :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.