473,246 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

ksort


Hi!

after I fill the fields with the names of the users and count the number of
the same users
( array_count_values( )
and sort them with ksort()
it doesn't put the user that repeats the most often at the top

What am I doing wrong?

$name=array();

while ($listname= mysql_fetch_assoc($score))
{

$name[] = $listname['user_name'];
}

mysql_free_result($score);

$name = array_count_values($name);

ksort($name);
while (list($key, $val) = each($ime)) {
{

echo "Name:$key \n";
}

thanks

Jul 17 '05 #1
2 2299
Fill wrote:
it doesn't put the user that repeats the most often at the top


Try krsort.

Jul 17 '05 #2
Fill wrote:
$name=array();

while ($listname= mysql_fetch_assoc($score))
{

$name[] = $listname['user_name'];
}

mysql_free_result($score);

$name = array_count_values($name);

ksort($name);
while (list($key, $val) = each($ime)) {
{

echo "Name:$key \n";
}


Actually, after looking at the code, I'd do it differently:
<?php
$name=array();
while ($listname= mysql_fetch_assoc($score)){
if(isset($name[$listname['user_name']])){
$name[$listname['user_name']]++;
}else{
$name[$listname['user_name']]=1;
}
}
arsort($name);
while(list($key,$val)=each($name)){
echo "Name: $key\n";
}
?>

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phil Powell | last post by:
$fbArray = array($feedbackCategoryArray => $feedbackCategoryArray); I can't begin to fathom in my befuddled mind how to sort this array $fbArray into alphabetical order according to...
7
by: lawrence | last post by:
Suppose I create dynamic web pages with 3 functions (which call other functions to make everything happen, but these 3 you might think of as being the top layer): registerSessions();...
9
by: Afanasiy | last post by:
This is fairly simple in PHP, how do I do it in Python? http://www.php.net/manual/en/function.ksort.php
210
by: Christoph Zwerschke | last post by:
This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an "ordered dictionary" class at least in the standard list? Time and again...
5
by: brewthom | last post by:
I'm new to php and am trying to bring in code from a text list in REVERSE order. I understand that I need to use ksort, but apparenlty am not understanding where to use this. The code below works,...
1
by: aRTx | last post by:
<? /* Directory Listing Script - Version 2 ==================================== Script Author: Artani <artan_p@msn.com>. www.artxcenter.com REQUIREMENTS ============ This script requires...
10
Ajm113
by: Ajm113 | last post by:
Making a History Page for BIG Sites Intro: Ok, let's say after a while your website has grown massive. We're talking search engine, forum and video hosting -- you've got a LOT of content. And you...
7
by: Ja NE | last post by:
(as first - thank you for all your help several years ago, and second - please apologise me for my clumsy enlgish) so, preface: some users on my photo related site sometimes enter (link) giant...
3
by: malcsman | last post by:
Hi there, I think it's best to explain things first.. (it's a sermons archive) I manage a static page which I'd like to automate. This page is an archive that lists mp3s and their notes(pdf) as...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.