473,915 Members | 6,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ksort


Hi!

after I fill the fields with the names of the users and count the number of
the same users
( array_count_val ues( )
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_ass oc($score))
{

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

mysql_free_resu lt($score);

$name = array_count_val ues($name);

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

echo "Name:$key \n";
}

thanks

Jul 17 '05 #1
2 2328
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_ass oc($score))
{

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

mysql_free_res ult($score);

$name = array_count_val ues($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_ass oc($score)){
if(isset($name[$listname['user_name']])){
$name[$listname['user_name']]++;
}else{
$name[$listname['user_name']]=1;
}
}
arsort($name);
while(list($key ,$val)=each($na me)){
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
11769
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 $feedbackCategoryArray - I am utterly lost, can someone explain in detail how I would do it and why. Thanx Phil
7
7833
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(); sendHtmlToBrowsers(); incrementPageViews(); Is there any chance that incrementPageViews() will be executed? Or, to
9
16783
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
10651
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 I am missing that feature. Maybe there is something wrong with my programming style, but I rather think it is generally useful. I fully agree with the following posting where somebody complains why so very basic and useful things are not part...
5
2422
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, but what I'd like it to do is list the most recently added items at top. I tried ksort($name) before the echo "a href..." statement. It didn't work. I know I'm missing something. Trying to figure it out. Like I said-- just learning. Thanks in advance....
1
4160
by: aRTx | last post by:
<? /* Directory Listing Script - Version 2 ==================================== Script Author: Artani <artan_p@msn.com>. www.artxcenter.com REQUIREMENTS ============ This script requires PHP and GD2 if you wish to use the
10
10551
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 are wondering, "Why do I need yet another feature for my big site?" Well, some people can become forgetful every time they see content on your site, and let's suppose that one day they needed to work on a good php script for their class and they...
7
5168
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 photo in their post or coment, and while I was writting new bbcode for my forum, I have got idea to check size of linked pictures to scale them down if needed (matamethic of that part isn't written in folowing code and would not be a problem). ...
3
1606
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 well as zip files. Every week i have to add two new mp3s and their pdf notes, remove entries and add a zip. if you'd like to see what it looks like, to maybe understand me: http://www.eastside.org.za/index.php?pageid=1552 each file type is in a...
0
10039
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10928
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7259
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4346
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.