Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Dynamic linking within content



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

10+ Year Member

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)

10+ Year Member


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;


Featured Threads

Hot Threads This Week

Hot Threads This Month