destrugter
07-07-2008, 10:26 PM
Ok, I am making my own forums, and I want to make it to where when the user puts something in, such as [user posts=destrugter] it connects to my database and grabs my posts, and displays them in the post...not the actual posts, the amount of posts...then if I post something after that post it will automatically update with the database. Here is the code I have so far (just ignore the basic bbcode tags).
<?php
function BBCodes($str) {
$str = htmlentities($str);
$simple_search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[url\=(.*?)\](.*?)\[\/url\]/is',
'/\[smiley\=(.*?)\]/is',
'/\[user posts\=(.*?)\]/is'
);
$simple_replace = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<a href="$1">$2</a>',
'<img src="../imgs/smilies/$1.gif"></img>',
Get_Posts("$1")
);
// Do simple BBCode's
$str = preg_replace($simple_search, $simple_replace, $str);
return $str;
}
function Get_Posts($Username) {
$result = mysql_query("SELECT * FROM `Users` WHERE `Username` = '". $Username ."'");
while($row = mysql_fetch_array($result))
{
return $row['Posts'];
}
}
?>
I am not going to actually allow users to post that...it's just a simple thing I started off with to make sure I know how it works for the bigger project. Can someone please tell me what I did wrong?
I have the post as:
Destrugter has: [user posts=destrugter] posts.
When it goes through and replaces for the BBCodes it does this:
Destrugter has: posts.
But when I remove the where section from the mysql_query, it grabs the first username to appear and that works...but I don't want the first user, I want the one specified by the poster.
<?php
function BBCodes($str) {
$str = htmlentities($str);
$simple_search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[url\=(.*?)\](.*?)\[\/url\]/is',
'/\[smiley\=(.*?)\]/is',
'/\[user posts\=(.*?)\]/is'
);
$simple_replace = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<a href="$1">$2</a>',
'<img src="../imgs/smilies/$1.gif"></img>',
Get_Posts("$1")
);
// Do simple BBCode's
$str = preg_replace($simple_search, $simple_replace, $str);
return $str;
}
function Get_Posts($Username) {
$result = mysql_query("SELECT * FROM `Users` WHERE `Username` = '". $Username ."'");
while($row = mysql_fetch_array($result))
{
return $row['Posts'];
}
}
?>
I am not going to actually allow users to post that...it's just a simple thing I started off with to make sure I know how it works for the bigger project. Can someone please tell me what I did wrong?
I have the post as:
Destrugter has: [user posts=destrugter] posts.
When it goes through and replaces for the BBCodes it does this:
Destrugter has: posts.
But when I remove the where section from the mysql_query, it grabs the first username to appear and that works...but I don't want the first user, I want the one specified by the poster.