Endless Paradigm

Full Version: Need help with php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
YAY ITS WORKING! THANK YOU, but its not {$username}, your function checks {username} so its {username} not with $, i want to try this by my self, i want it just with hex color, but let me try this from not on, if i need more help i will post.

You said that its slow, how can i put it faster? creating a file with the database part and put require_once filename at the begin of the functions.php?

EDIT, ok its working well now, no need to put the span, etc, just #hexcolor.

THIS IS AWESOME, THANK YOU SO MUCH, i just don't know how to put things faster, it isn't slow because its just one user, but if i have more users using that it will probably be slow. Im using the cache folder as cache instead of db, and im using the css folder for css, so it doesn't requires the db too often. but what do you do to increase the speed?
Ok i put the font working too:

PHP Code:
function format_name($username, $usergroup, $displaygroup="")
{
    global $db;
    $queryC = $db->query("SELECT fid5 FROM ".TABLE_PREFIX."userfields f LEFT JOIN ".TABLE_PREFIX."users u ON u.uid = f.ufid WHERE u.username = '".$db->escape_string($username)."'");
	$queryF = $db->query("SELECT fid6 FROM ".TABLE_PREFIX."userfields f LEFT JOIN ".TABLE_PREFIX."users u ON u.uid = f.ufid WHERE u.username = '".$db->escape_string($username)."'");
    $color = $db->fetch_field($queryC, 'fid5');
    $font = $db->fetch_field($queryF, 'fid6');
	
	if($color && $font)
	{
		$format = "<span style=\"color:{$color};\"><span style=\"font-family:{$font}\">{username}</span></span>";
	}
	
	if($font && !$color)
	{
		 $format = "<span style=\"font-family:{$font}\">{username}</font>";
	}
	
	if($color && !$font)
	{
		 $format = "<span style=\"color:{$color}\">{username}</span>";
	}

	$userin = substr_count($format, "{username}"); // function that counts how many times {username} substring is in the $formats string
    if($userin == 0) // if {username} substring wasnt found in the $format string, then
    {
        $format = "{username}"; // the $format string = "{username}"
    }
    return str_replace("{username}", $username, stripslashes($format));
}


But asi disabled some plugins it still fast, and i already have some users using font and color. How do i speed up the site? as you said that will slow down.

The speed will depend on some things.
The main issue is the number of SQL queries run.  Let's say there's 30 users in the "who's online today" list - 30 queries must be done to perform the formatting.
Doesn't matter how you do it, your method will require a lot of queries.  If it doesn't make it noticeably slower, well then stick with it.

The cache store in files only affects the datacache (the mybb_datacache table).


My implementation actually doesn't require any new queries.  It does require about 30 code edits however.  Speed is basically unaffected.
Also my implementation allows extra code to be inserted manually by me, which is how I rigged hibbyware's posts :P
ooooooooooooooooooooo ok, you should put username size too.
Lol@hibby posts.
what did you do to don't use the database?
It uses the database, but doesn't perform any extra queries.  I just modified existing queries to allow it to retrieve name formatting info.  In fact, the only thing changed was retrieving an extra field (no new joins are created), which is why speed is basically unaffected.

As I said, it does require a lot of code edits however.
ok thanks anyway. i have a doubt, can't i save the info in one file instead of using the db?
^ You can if you want.  Really more work than necessary, and probably actually slows down everything even more...
lol ok then.
hi again , sry if im annoying you too much, but can you tell me how you did it?? like you did with muppet modding, if you could tell me....:D :D :please:
Pages: 1 2 3 4
Reference URL's