MyBB Community Forums

Full Version: Page Manager | Add Profile Field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is it possible to add a profile field to the page manager plugin and make it show? Right now I'm using the code SvePu gave:
(2017-02-08, 06:33 PM)SvePu Wrote: [ -> ]Import the xml file with PageManager plugin and you'll see the clear code.....exported page XMLs are encoded.

But here also is the script for the PM page (without using MyBB Templates):
<?php

global $headerinclude, $header, $theme, $footer, $db;

$altbg = alt_trow();
$userlist = '';
$query = $db->simple_select("users", "*", "usergroup IN ('2','4')", array("order_by" => 'username', "order_dir" => 'ASC'));
 
 while($users = $db->fetch_array($query))
 {
 $username = build_profile_link(format_name(htmlspecialchars_uni($users['username']), $users['usergroup'], $users['displaygroup']), $users['uid']);
 
 $userlist .= '<tr><td class="'.$altbg.'">'.$username.'</td></tr>';
 $altbg = alt_trow();
 }

$template='<html>
<head>
<title>'.$pages['name'].'</title>
{$headerinclude}
</head>
<body>
{$header}
<table border="0" cellspacing="'.$theme['borderwidth'].'" cellpadding="'.$theme['tablespace'].'" class="tborder">
<thead>
<tr>
<td class="thead">
<strong>'.$pages['name'].'</strong>
</td>
</tr>
</thead>
<tbody>
{$userlist}
</tbody>
</table>
<br />
{$footer}
</body>
</html>';

$template=str_replace("\'", "'", addslashes($template));

add_breadcrumb($pages['name']);

eval("\$page=\"".$template."\";");

output_page($page);

?>
I was wondering if I could pull a profile field from the database and display what they have in that profile field?

It would have their name in the userlist and then right behind their name would be the profile field for sex for example.
I've tried looking around for the code to pull a profile field but all of them seem so complicated I'm not sure if I'm looking at the right thing. 

If you know the answer can you explain it as well as give the coding so I can learn?

Thanks in advance!! Smile
Try this as content of PageManager page:
<?php

global $headerinclude, $header, $theme, $footer, $db;

$altbg = alt_trow();
$userlist = '';
$query = $db->query("
		SELECT u.*, uf.fid3 as usersex
		FROM ".TABLE_PREFIX."users u
		LEFT JOIN ".TABLE_PREFIX."userfields uf ON (uf.ufid=u.uid)
		WHERE u.usergroup IN ('2','4') AND uf.fid3 != ''
		ORDER BY u.username ASC
	");
 
 while($users = $db->fetch_array($query))
 {
	$username = build_profile_link(format_name(htmlspecialchars_uni($users['username']), $users['usergroup'], $users['displaygroup']), $users['uid']);
	$usersex = htmlspecialchars_uni($users['usersex']);

	$userlist .= '<tr>
			<td class="'.$altbg.'">'.$username.'</td>
			<td class="'.$altbg.'">'.$usersex.'</td>
		</tr>';
	$altbg = alt_trow();
 }

$template='<html>
	<head>
		<title>'.$pages['name'].'</title>
		{$headerinclude}
	</head>
	<body>
		{$header}
		<table border="0" cellspacing="'.$theme['borderwidth'].'" cellpadding="'.$theme['tablespace'].'" class="tborder">
			<thead>
				<tr>
					<td class="thead" colspan="2"><strong>'.$pages['name'].'</strong></td>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td class="tcat" width="70%">Username</td>
					<td class="tcat" width="30%">Sex</td>
				</tr>
				{$userlist}
			</tbody>
		</table>
		<br />
		{$footer}
	</body>
</html>';

$template=str_replace("\'", "'", addslashes($template));

add_breadcrumb($pages['name']);

eval("\$page=\"".$template."\";");

output_page($page);

?>
That works wonderfully, but it seems if a user hasn't 'set' a sex for their profile the name won't even show either.

Is it possible to still have the name show even if the profile field is not filled out?

Also, thank you for the help. The code I was looking at is VERY different from this one and much more complicated.
(2017-02-21, 06:56 PM)isoldehn Wrote: [ -> ]...
Is it possible to still have the name show even if the profile field is not filled out?
......
Simply remove from the SQL query WHERE clause: Wink

AND uf.fid3 != ''
Oh this is awesome, okay, thank you VERY much for this help!!