tags:

views:

32

answers:

2

Hello,

I have a PHP script that pulls keywords from a MySQL database and I need help with figuring out how to link each word.

An example MySQL entry: cow moo white black

Need to output in link form:

<a href=word.php?word=cow>cow</a> <a href=word.php?word=moo>moo</a>, etc.

Thank you

+1  A: 

If $row["entry"] is the entry, then as follows:

   $fieldArray = split(" ", $row["entry"]);

    foreach($fieldArray as $item) {
      echo "<a href=\"word.php?word=" . $item . "\">" . $item . "</a>";
    }
Goat Master
Thats it! Thank you Goat Master! :)
AZKyleP
+1  A: 

Try this:

$output = "";
$mysql_str = "cow moo white black";
$keywords = explode(" ", $mysql_str);

foreach ($keywords as $keyword) {
  $output .= "<a href=\"word.php?word=".$keyword."\">".$keyword."</a> ";
}

echo $output;
redhatlab
Thank you redhatlab! Goat Master answered it before you so I have to give him the Answer. Sorry but thank you for taking the time to help me.
AZKyleP
No a problem. BTW split is a deprecated function on PHP 5.3, it might become an issue on the future: http://us.php.net/split Also Goat Master "foreach" loop print out the linked words twice.
redhatlab
You got the answer. I tried his code first but ran into some issues with it. Your code worked like a charm! Thank you very much! :) If you can edit your post please add an "o" to explde incase someone else finds this post useful.
AZKyleP
o added. Thank you.
redhatlab