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
well the member.php has the $usefields varaible, and i can use the $userfields variable there without doing anything i just need to do what i did in my code.

Like this per example:
Replace this:

PHP Code:
$formattedname = format_name($memprofile['username'], $memprofile['usergroup'], $memprofile['displaygroup']); 


with this:

PHP Code:
    if($userfields['fid5'])
    {
        $formattedname = "<span style=\"color:{$userfields['fid5']}\">{$memprofile['username']}</span>";
    }
    else
    {
        $formattedname = format_name($memprofile['username'], $memprofile['usergroup'], $memprofile['displaygroup']);
    } 


So this is my function now:

PHP Code:
function format_namePN($username, $usergroup, $displaygroup="")
{
    global $groupscache, $cache, $db;
	
	$query = $db->simple_select("SELECT * FROM userfields");
    $userfields = $db->fetch_field($query);

    if(!is_array($groupscache))
    {
        $groupscache = $cache->read("usergroups");
    }

    if($displaygroup != 0)
    {
        $usergroup = $displaygroup;
    }

    if($userfields['fid5')
    {
        $format = "<span style=\"${userfields['fid5'};\">{username}</span>";
    }
    else
    {
        $ugroup = $groupscache[$usergroup];
        $format = $ugroup['namestyle'];
    }
    $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}"
    }
    $format = stripslashes($format); // The stripslashes() function removes backslashes from the $format string
    return str_replace("{username}", $username, $format); // replaces {username} with $username, so the $format string will contain $username instead of {username}
} 


Still not working.

And its  $format = "<span style=\"${userfields['fid5'};\">{username}</span>"; not  with &#092

Uhh....  the two functions kinda contradict each other...  Try working through your logic first.
but i know what im doing and i know what to edit but i don't know what i need to acess userfields.

Also what functions contradict each other?
Well, if you know what you're doing, you obviously don't need help! :P

*sigh* okay, I'll give you a quick 1 minute function (too lazy to test if it works).  It _should_ work, but do note that it's _very_ slow:

PHP Code:
function format_name($username, $usergroup, $displaygroup="")
{
	global $db;
	$query = $db->query("SELECT fid5 FROM ".TABLE_PREFIX."userfields f LEFT JOIN ".TABLE_PREFIX."users u ON u.uid = f.uid WHERE u.username = '".$db->escape_string($username)."'");
	
	if(!strpos($format = $db->fetch_field($query, 'fid5'), '{username}'))
	{
		global $groupscache, $cache;

		if(!is_array($groupscache))
			$groupscache = $cache->read("usergroups");

		if($displaygroup) $usergroup = $displaygroup;
		
		if(!strpos(($format = $groupscache[$usergroup]['namestyle']), '{username}'))
			$format = "{username}";
	}
	return str_replace("{username}", $username, stripslashes($format));
}

i don't think that's what i want, i just want users to insert the hex color, not the <span style="{$userfields['fid5'};">{username}</span>

I tested that:
MySQL error: 1054
Unknown column 'f.uid' in 'on clause'
Query: SELECT fid5 FROM mybb_userfields f LEFT JOIN mybb_users u ON u.uid = f.uid WHERE u.username = 'GoogleBot'
also i tried that in the function format_name instead of format_namePN
and i get this error:
MySQL error: 1054
Unknown column 'f.uid' in 'on clause'
Query: SELECT fid5 FROM mybb_userfields f LEFT JOIN mybb_users u ON u.uid = f.uid WHERE u.username = 'Pirata Nervo'
Well, if it's not called "uid" replace it with the proper name.  I'm too lazy to look up what the correct name is.

If you don't want people entering a <span> then just remove it...
Ok this is how it is:
f.ufid

No errors shown, BUT, nothing changed.
Also remove what? the span???
Doesn't your function requires people to insert <span style="#hexcolorhere;">{username}</span> instead of just #hexcolor?
Urgh, okay, tell me what do you have in fid5?

Try setting it to something like:

Code:
<span style="color: red;">{$username}</span>


Let's take this one step at a time.

I have #ff0000.

ok let me try with that.
Pages: 1 2 3 4
Reference URL's