Hello all. I've got a question hopefully I can get a lil help on. Im sort of a PHP novice
Background:
I've created an app in flex that utilizes ZendAMF to make php calls to a db to pull information. the php queries the info it puts all the fields from each record into an object that then gets put into an array thats returned to flex which is then displayed in a datagrid. which Ive been able to get to work fine. 2 of the fields in each record are an agent name and a numerical amount.
Question:
there is a good chance that the agent name will appear more than once as a name variable in each object in the array but the numerical amount which is a price variable in the object could differ from object to object. What i want to do if possible is filter the array and throw out the duplicate object->name object but before disposing of them add all of the price variables of that particular agent, putting it into a total variable of the object and then returning that object so that flex will display in the data grid the agent name once but the total numerical number.
please let me know if this is possible of if this question isnt concise enough and there are questions on my question heh. Thanks to anyone that helps.
Filtering through an array for duplicates...lil help
Moderator: General Moderators
-
hpnotiqtymes
- Forum Newbie
- Posts: 2
- Joined: Fri Jul 03, 2009 9:54 pm
Re: Filtering through an array for duplicates...lil help
You can do it quite easily in your SQL query.
What is it right now?
What is it right now?
-
hpnotiqtymes
- Forum Newbie
- Posts: 2
- Joined: Fri Jul 03, 2009 9:54 pm
Re: Filtering through an array for duplicates...lil help
Code: Select all
$query = "SELECT * FROM sales WHERE `Date` BETWEEN '$newStart' AND '$newEnd'";Re: Filtering through an array for duplicates...lil help
In general you should only be SELECTing the fields you want.
You can use the GROUP BY clause and SUM function to group the results by person while summing up the prices.
The results will also be sorted by person; if you don't want that add an ORDER BY to the query as well.
You can use the GROUP BY clause and SUM function to group the results by person while summing up the prices.
Code: Select all
SELECT fields, person, SUM(price) AS price FROM sales WHERE `Date` BETWEEN '$newstart' AND '$newend' GROUP BY person