Jump to content

[SOLVED] Filtering through an array for duplicates...lil help


hpnotiqtymes

Recommended Posts

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.

Link to comment
Share on other sites

Thx. Ill give it a try. where it saids in the query Sum as price_total, just to make sure i get it in my memory banks, is just taking the sum and putting it into a temporary field called price_total that i can then call in the php script and do something like:

 

while ( $row = mysql_fetch_object($result) )
{
   $temp->total = $row->price_total;
}

Link to comment
Share on other sites

I just realized where using this method might be a problem. Please correct me if i dont know what the heck im talking about but as far as the query goes im already pulling the information using this query

$query = "SELECT * FROM sales WHERE `Date` BETWEEN '$newStart' AND '$newEnd'";

 

i first pull from the db using a this query as i need the info for the current week. then i need to filter through the info to find the entries of the same agent then add up the numerical values.

 

Link to comment
Share on other sites

Like I said, you want to accomplish this with your query.

 

Here is what your query should look like (I am making an assumption that your agent and price fields are named accordingly - change them as needed.

$query = "SELECT *, SUM(price) as price_total
          FROM sales
          WHERE `Date` BETWEEN '$newStart' AND '$newEnd'
          GROUP BY agent";

 

Now in your code which prits the results, use price_total instead of price

Link to comment
Share on other sites

I would like to say that u my friend are the man. It worked perfectly. I appreciate it I'm not used to doing things like that with queries. lol all the things Ive done with queries are really simple which is pretty much selecting all. lol the get between the 2 dates is probably the most complex query ive done which is pretty sad. 10 cool pts to you..again thx a bunch..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.