473,396 Members | 1,758 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,396 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 2310
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.