MyBB Community Forums

Full Version: Need Help With PHP Code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here's a snippet of the file:
	$query = $db->query("SELECT * FROM `".TABLE_PREFIX."banned` ORDER BY `dateline` DESC");
	while ($banned = $db->fetch_array($query))
	{
	$uid = intval($banned['uid']);
	$user = get_user($uid);
	$bannedmember = build_profile_link($user['username'],$banned['uid']);
	}
	$query = $db->simple_select("banned", "COUNT(uid) AS count");
	$totalbanned = $db->fetch_field($query, "count");

		$template = "<html>
		<head>
		<title>Banned Members</title>
		{$headerinclude}
		</head>
		<body>
		{$header}
		<table class=\"tborder\" cellpadding=\"4\" cellspacing=\"1\" border=\"0\">
		<tr>
		<td class=\"thead\"><strong>Banned Members</strong></td>
		</tr>
		<tr>
		<td class=\"tcat\" width=\"23%\"><span class=\"smalltext\">Below is the list of all banned members.</span></td>
		</td>
		</tr>
		<td class=\"trow1\"><span class=\"smalltext\">
				
		{$bannedmember}
		
		</span></td></table>
		<br />
		Total Banned Members: <b>{$totalbanned}</b>
		{$footer}
		</body>
		</html>";

It should display all banned members, but it does not.
Screenshot:
[Image: ne7PI.png]
Try this:
$query = $db->simple_select("banned", "COUNT(uid) AS count");
$totalbanned = $db->fetch_field($query, "count");

$i = 1;

$query = $db->query("SELECT * FROM `".TABLE_PREFIX."banned` ORDER BY `dateline` DESC");
while($banned = $db->fetch_array($query))
{
	if($i < $totalbanned)
	{
		$seperate = ', ';
	}
	else
	{
		$seperate = '';
	}

	$uid = intval($banned['uid']);
	$user = get_user($uid);
	$bannedmember = build_profile_link($user['username'],$banned['uid']);
	
	$bannedmembers .= $bannedmember.$seperate;
	
	$i++;
}
	$template = "<html>
	<head>
	<title>Banned Members</title>
	{$headerinclude}
	</head>
	<body>
	{$header}
	<table class=\"tborder\" cellpadding=\"4\" cellspacing=\"1\" border=\"0\">
	<tr>
	<td class=\"thead\"><strong>Banned Members</strong></td>
	</tr>
	<tr>
	<td class=\"tcat\" width=\"23%\"><span class=\"smalltext\">Below is the list of all banned members.</span></td>
	</td>
	</tr>
	<td class=\"trow1\"><span class=\"smalltext\">
			
	{$bannedmembers}
	
	</span></td></table>
	<br />
	Total Banned Members: <b>{$totalbanned}</b>
	{$footer}
	</body>
	</html>";
Also, to save a database query, use $query->num_rows to grab the number of total banned users from the query you used to grab all of the banned users. This will only work, however, assuming that you want to display every banned user in the box. If you wanted to later limit the number of members it viewed, you'd need to go back to using a separate query.

	//$query = $db->simple_select("banned", "COUNT(uid) AS count");
	//$totalbanned = $db->fetch_field($query, "count");

	$query = $db->query("SELECT * FROM `".TABLE_PREFIX."banned` ORDER BY `dateline` DESC");
	$total_banned = $query->num_rows;

Obviously this isn't really needed on a small forum, but efficiency can always help.