Jump to content

preg and some mysql


gibbo101

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/192470-preg-and-some-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.