homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Dynamic linking within content

 10:40 am on Jan 16, 2006 (gmt 0)

Hi Everyone,

I've got problem which I've so nearly solved but I have a couple issues.

What's happening, is that it displays the news item twice because there are 2 keywords in the DB, so I'm trying to resolve that, I think that might be the problem?

Then when it displays the article first time round it then places links on the first keyword in the DB. And then when it displays the article second time round it places links according to the second keyword in the DB, but not the first keyword in the DB as well.

So it might be something to do the with the looping?

Any ideas anyone?


Woldie. :o)

Here's the code:

$result=mysql_query("select main_story
from tbl_news
where nwsid=1");
list ($DBmain_story)=mysql_fetch_row($result);

$bits=explode(" ",$DBmain_story);

for ($x=0;$x < count($bits);$x++)

$result1=mysql_query("select keyword,url
from tbl_keyword");
while (list($DBkeyword,$DBurl)=mysql_fetch_row($result1))
for ($y=0;$y < count($final_words);$y++)
if ($DBkeyword==$final_words[$y])
$test.=' '."<a href=\"$DBurl\">".$DBkeyword."</a>" .' ';
$test.=' '.$final_words[$y].' ';
echo $test;



 9:22 am on Jan 19, 2006 (gmt 0)


Okay, I've got it to work...

Here's the code, just in case anyone whose interested. Just to re-iterate, this places links on the fly according to what keywords you have in the DB.


If anyone has any comments, then feel free to post.


$result1=mysql_query("select keyword,url
from tbl_keywords");
while (list($DBkeyword,$DBurl)=mysql_fetch_row($result1))
$replace_string = "<u><a href=\"$DBurl\">$DBkeyword</a></u>";
$DBmain_story = str_replace(' ' . $DBkeyword. ' ', ' ' . $replace_string . ' ', $DBmain_story);
echo $DBmain_story;

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved