0

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

2
  • All the keywords in the 1 MySQL row need to be turned into links upon output. Commented Oct 17, 2010 at 4:18
  • Sorry if I didn't answer your question. There is spaces in the MySQL rows. Everything between the spaces needs to be turned into a link. Commented Oct 17, 2010 at 4:21

2 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

3 Comments

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.
No a problem. BTW split is a deprecated function on PHP 5.3, it might become an issue on the future: us.php.net/split Also Goat Master "foreach" loop print out the linked words twice.
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.
1

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>";
    }

1 Comment

Thats it! Thank you Goat Master! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.