gibbo101 Posted February 18, 2010 Share Posted February 18, 2010 Hi, Im tring to enable an [id=X] bbtag for my website where the ID tag will display the name and link of a player. This represents a problem as I need to call from mysql the players name (and if they are staff their staff title and name color). So far I've got this: <?php function bbID($text) { $bbcode="/\[id\](.*?)\]/is"; $bbcode1="$1"; $bbcode1=preg_replace ($bbcode, $bbcode1, $text); $query=mysql_query("SELECT * FROM users WHERE id='$bbcode1'"); $row=mysql_fetch_array($query); if ($row[staff]!='0') { $bbcode2="<div id='link'><a href='game.php?&action=view&pid=$1'><b><font color='$row[staff_color]'>$row[staff] $row[char_name]</font></b></a></div>"; } elseif ($row[service_user]!='0') { $bbcode2="<div id='link'><a href='game.php?&action=view&pid=$1'><font color='$row[service_color]'>$row[char_name]</font></a></div>"; } else { $bbcode2="<div id='link'><a href='game.php?&action=view&pid=$1'>$row[char_name]</font></a></div>"; } $text= preg_replace ($bbcode, $bbcode1, $text); return $text; } It works great apart from 1 problem. The links for each player is fine. However if I were to enter [id=1] [id=2] I get returned the name of player 1 twice, although the links send me to player 1 and 2 respectively. Any ideas on this? Quote Link to comment Share on other sites More sharing options...
cags Posted February 18, 2010 Share Posted February 18, 2010 So you need to alter the replacement string based on a value in the database? You'll probably need to use preg_replace_callback. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.