473,396 Members | 2,004 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.

Filter array based on a value from another row?

Hello,

I am pulling values from a data table and ranking them. My data table has the following columns:

value | statistic_id | player_id | day | id

The value is the value for the particular statistic. It is a number
The statistic_id is the statistic being tracked. It is a number.
The player_id is the id for a player. It is a number.
The day is the day the value is inserted.
The id is an auto_increment index.

I am trying to rank and then filter my data. I've figured out how to rank the data. Here is the code to rank my data:

Expand|Select|Wrap|Line Numbers
  1. <?
  2.   $statistic_id = $_GET['s'];
  3.   $pid = $_GET['p'];
  4.   include 'index.php';
  5.  
  6.   $sql = sprintf('SELECT * FROM data WHERE day = CURdate()-INTERVAL 1 day AND statistic_id = %d', $statistic_id);
  7.   $result = mysql_query( $sql );
  8.   $array = array();
  9.   while( $obj = mysql_fetch_object( $result ) )  {
  10.   $array[ $obj->player_id ] = $obj->value;
  11.   }
  12.  
  13.   function getNameFromId ( $player_id ) {
  14.     $sql = sprintf( 'SELECT name FROM players WHERE id = %d', $player_id );
  15.     $res = mysql_query( $sql );
  16.     $arr = mysql_fetch_array( $res );
  17.     return $arr[ 'name' ];
  18.   }
  19.  
  20.   arsort( $array );
  21.  
  22.   $i = 0;
  23.   foreach ( $array as $player_id => $value ) {
  24.   $i++;
  25.   $player_name = getNameFromId ( $player_id );
  26.   echo sprintf( "\n%s is ranked %d with a value of %s <br/>", $player_name, $i, $value );
  27.    }
  28. ?>
  29.  
I would like to be able to filter this ranked data based on ANOTHER statistic_id. So, for example.

value | statistic_id | player_id | day | id
1 | 1 | 1 | 2010| 1
2 | 1 | 2 | 2010| 2
3 | 2 | 1 | 2010| 3
2 | 2 | 2 | 2010| 4

Given this data, I have already been able to rank by statistic_id 1 so that the order goes
1) player_id 2 - value
2) player_id 1 - value

I would then like to filter by statistic_id 2 so that only values greater than 2 show in my ranked list based on statistic_id 1. Given this filter, only player_id 1 would show:
1) player_id 1 - value

If you need more clarification, please ask. If you have any methods on how this can be accomplished I would be very appreciative!

Thanks!
Sep 28 '10 #1
0 1200

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: LRW | last post by:
Subject line confusing? The whole thing is confusing to me. OK, I think the root of my problem, aside from mental, is array based...but I'm not even sure what I want to do is even possible. So if...
4
by: Chris Mabee | last post by:
Hello all, and Merry Christmas, I'm having a problem understanding an example of an array based implementation of a stack in a textbook of mine. The code in question is written below. The syntax...
11
by: Matt | last post by:
Hi everyone, still pretty new to MySQL. I was wondering if there is a way to automatically filter records based on a mysql userlogin name?? I have serveral databases that I want to combine in...
1
by: kieran | last post by:
Hi, I have a string Array called Groups and this has x number of groups. Each row of the Array is divided up by ';' and has the name of the group in the second position (i.e. after the first...
3
by: turtle | last post by:
I have Two tables (Table1 and Table2). Both tables have a common field called part number. Table 1 contains an extra field that i would like to update table 2 to match if the part number matches....
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
1
by: gr8gatzb | last post by:
I have 2 arrays that are related. The first array is an array of distances from a certain spot. The second array is an array of city names. They are related in that the order of the distances array...
94
by: mlcampeau | last post by:
I have a report (JobVacanciesOnly) that has a subreport (JobVacanciesOnlySR) that are based on two separate queries. MY - JobVacancyJobs SELECT Job.Code, Job.Title, Job.Grade, Grade.Minimum,...
4
WyvsEyeView
by: WyvsEyeView | last post by:
I am doing the very standard thing of filtering the contents of one combo box based on another combo box. I've done it many times, but always on a main form. Now I'm trying to do it on a datasheet...
3
by: tasawer | last post by:
Hi, I have an accident claims form that I need to requery on one of three different fields. Primary field is AccidentID ClientName (Can appear on more than one AccidentID) SolicitorsRef...
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
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...
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.