473,385 Members | 1,564 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,385 software developers and data experts.

Stumped by Array problem!!

18
Hi, hope I can explain this clearly. I have the following query and results, no problems here:

[PHP]
$query = 'SELECT SUM(ed) AS ed, SUM(ted) AS ted, SUM(tom) AS tom FROM week ';
$result = mysql_query($query) or die(mysql_error());

$values['ed']['sum'] = mysql_result($result, 0, "ed");
$values['ted']['sum'] = mysql_result($result, 0, "ted");
$values['tom']['sum'] = mysql_result($result, 0, "tom");

$values['ed']['name'] = mysql_field_name($result, 0);
$values['ted']['name'] = mysql_field_name($result, 1);
$values['tom']['name'] = mysql_field_name($result, 2);[/PHP]

I then have this code which puts the results of the "sum" data into an array and sorts it. This works fine as well.

[PHP]
$edsum = $values['ed']['sum'];
$tedsum = $values['ted']['sum'];
$tomsum = $values['tom']['sum'];

$edname = $values['ed']['name'];
$tedname = $values['ted']['name'];
$tomname = $values['tom']['name'];

$temp = array("$edsum", "$tedsum", "$tomsum");
array_multisort($temp, SORT_NUMERIC, SORT_DESC);[/PHP]

What I CAN'T figure out is how to get the "name" data into the array as well. I need to output the "name" and "sum" data together sorted. Any ideas would be greatly appreciated!!!!!

Thanks, Tom
Feb 19 '07 #1
3 1093
cassbiz
202 100+
Hi, hope I can explain this clearly. I have the following query and results, no problems here:

[PHP]
$query = 'SELECT SUM(ed) AS ed, SUM(ted) AS ted, SUM(tom) AS tom FROM week ';
$result = mysql_query($query) or die(mysql_error());

$values['ed']['sum'] = mysql_result($result, 0, "ed");
$values['ted']['sum'] = mysql_result($result, 0, "ted");
$values['tom']['sum'] = mysql_result($result, 0, "tom");

$values['ed']['name'] = mysql_field_name($result, 0);
$values['ted']['name'] = mysql_field_name($result, 1);
$values['tom']['name'] = mysql_field_name($result, 2);[/PHP]

I then have this code which puts the results of the "sum" data into an array and sorts it. This works fine as well.

[PHP]
$edsum = $values['ed']['sum'];
$tedsum = $values['ted']['sum'];
$tomsum = $values['tom']['sum'];

$edname = $values['ed']['name'];
$tedname = $values['ted']['name'];
$tomname = $values['tom']['name'];

$temp = array("$edsum", "$tedsum", "$tomsum");
array_multisort($temp, SORT_NUMERIC, SORT_DESC);[/PHP]

What I CAN'T figure out is how to get the "name" data into the array as well. I need to output the "name" and "sum" data together sorted. Any ideas would be greatly appreciated!!!!!

Thanks, Tom

Hope I can help here

in the line
Expand|Select|Wrap|Line Numbers
  1. $temp = array("$edsum", "$tedsum","$tomsum");
  2.  
shouldn't it read

Expand|Select|Wrap|Line Numbers
  1. $temp = array("$edname","$edsum","$tedname", "$tedsum","$tomname","$tomsum");
  2.  
I am still somewhat a noob, but I noticed that the *name wasn't in your output.

Good luck
Feb 19 '07 #2
tom_b
18
Hope I can help here

in the line
Expand|Select|Wrap|Line Numbers
  1. $temp = array("$edsum", "$tedsum","$tomsum");
  2.  
shouldn't it read

Expand|Select|Wrap|Line Numbers
  1. $temp = array("$edname","$edsum","$tedname", "$tedsum","$tomname","$tomsum");
  2.  
I am still somewhat a noob, but I noticed that the *name wasn't in your output.

Good luck
Hi! Well, I've tried that, and some other variations with no luck. What that code gives me is the numbers first, sorted, then the names. I'm thinking I need to put each name and its' corresponding sum into one variable if I could but haven't had any luck yet. But thanks for your time!
Feb 19 '07 #3
Atli
5,058 Expert 4TB
You could set up your array like this.

[PHP]
$myArra = array(
"Ed" => array("Name" => $name1, "Sum" => $sum1),
"Bob" => array("Name" => $name2, "Sum" => $sum2),
"Bill" => array("Name" => $name3, "Sum" => $sum3)
// Yes i forgot the names :P
);

// Print Ed's info
echo "Name: ". $myArr['Ed']['Name'] ." - Sum: ". $myArr['Ed']['Sum'];
[/php]

Hope this helps.

Edit:
When I look back I think your initial $values array is set up like this.
Feb 19 '07 #4

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

Similar topics

1
by: Robert | last post by:
Im having a problem with an array that is put into a session. I want to be able to remove any element, but when I loop through to display them, it doesnt work right. I believe its because of the...
4
by: Andy Levy | last post by:
Hi I have a form which contains several fields. One of which is a group of checkboxes that can all be selected, and if they are - all values should be passed as an array. Each checkbox is...
2
by: Zenobia | last post by:
I have a problem. I need to look up several values stored in arrays. Each value is stored as a pair. The first (number) represents the probability of this item occurring. For instance, in the...
2
by: farmer | last post by:
I need to populate a listbox of other listview with selected listview items.although the following code works perfecty I want to use an Array (for various reasons) for Each ListItem In...
0
by: helldiversafe-news | last post by:
Hi all, I will use a apache soap service with an .net c# client and have a problem with an complex array: <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope...
2
by: julian_m | last post by:
let's say that I've an array like this: $AL_array = Array ( => Array ( => 1 ) , => Array ( => 2 ) , => Array ( => 3 ) , => Array ( => 4 ) , => Array ( => 1 ) , => Array ( => 2 )...
8
by: SpreadTooThin | last post by:
Basically I think the problem is in converting from a 32 bit integer to a 16 bit integer. I have two arrays: import array a = array.array('L', ) b = array.array('H', ) b = a
2
by: Toni | last post by:
I have ImageButton array. I have defined onClick event and it works. But in this function I can not use control propetries. I want to use index of ImageButton which is clicked and ImageURL...
3
by: Robert Bevington | last post by:
Hi all, I ran into memory problems while tying to search and replace a very large text file. To solve this I break the file up into chunks and run the search and replace on each chunk. This...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.