folgendes Problem: Ich lasse mir über diesen Codeblock ein Array füllen, dass der ID eines Forums die jeweilige Prozentzahl der erstellten Beiträge eines Benutzers bezogen auf die Gesamtzahl der Posts eines Forums zuordnet:
Code: Alles auswählen
//
// The users most active forum
//
$sql = "SELECT forum_id, forum_posts
FROM " . FORUMS_TABLE . "";
$result = $db->sql_query($sql);
while ( $row = $db->sql_fetchrow($result) )
{
$fids = $row['forum_id'];
$fposts = $row['forum_posts'];
// Second: get the user's post count for each forum
$sqlsub = "SELECT COUNT(post_id) AS posts
FROM " . POSTS_TABLE . "
WHERE poster_id = '" . $profiledata['user_id'] . "'
AND forum_id = '$fids'";
$resultsub = $db->sql_query($sqlsub);
while ( $rowsub = $db->sql_fetchrow($resultsub) )
{
$uposts = $rowsub['posts'];
$percentage = array();
if ( $uposts != '0' )
{
//
// Lets do some calculating work
//
$percentage['a'] = $uposts / $fposts;
$percentage[$row['forum_id']] = $percentage['a'] * 100;
}
else
{
$percentage[$row['forum_id']] = '0.00';
}
echo "Prozentsatz der Einzelforen: " . $row['forum_id'] . " " . $percentage[$row['forum_id']];
}
}
Das Sortieren per array_multisort() bereitet insofern Probleme, dass der zu sortierende Block bereits ein Array beinhaltet:
Code: Alles auswählen
//
// Lets do some calculating work
//
$percentage['a'] = $uposts / $fposts;
$percentage[$row['forum_id']] = $percentage['a'] * 100;
$percentage[$row['forum_id']] = array_multisort($percentage[$row['forum_id']], SORT_DESC, SORT_NUMERIC);
Somit ist auch keine Limitierung des Arrays machbar.
Wie lässt sich dieses Problem umgehen?[/code]