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
3 1093
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 -
$temp = array("$edsum", "$tedsum","$tomsum");
-
shouldn't it read -
$temp = array("$edname","$edsum","$tedname", "$tedsum","$tomname","$tomsum");
-
I am still somewhat a noob, but I noticed that the *name wasn't in your output.
Good luck
Hope I can help here
in the line -
$temp = array("$edsum", "$tedsum","$tomsum");
-
shouldn't it read -
$temp = array("$edname","$edsum","$tedname", "$tedsum","$tomname","$tomsum");
-
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!
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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 )...
|
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
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |