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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.