I'm trying to create a function that will replace names found in an article with links to more information about that person.
I would like to be able to call the names from a MySQL DB along with the unique ID that goes with each name and then replace the name in the article with the proper link
This is the code I have so far, it works to create a link, but not with the proper id, however I am not very familiar with the foreach() function. Any help would be greatly appreciated.
function name_link($message)
{
$i = 0;
$q = mysql_query("select first_name, last_name, id from players") or die(mysql_error());
while($a = mysql_fetch_array($q, MYSQL_BOTH))
{
$player_names[$i] = "$a[first_name] $a[last_name]";
$i++;
}
foreach($player_names as $player_name)
{
$link = "<a href=\"\">$player_names</a>";
$message = str_replace($player_name, $link, $message);
}
return $message;
}