Dear All,
If anybody can help a poor simpleton newbie I would really appreciate it.
It maybe the monday syndrome but nothing i do works!

I have a multi dimensional array made in the following manner.

$datasq["$part_no"]["item_ver"]="$item_ver";
$datasq["$part_no"]["po_id"]="$po_id";
$datasq["$part_no"]["weeky"]="$weeky";
$datasq["$part_no"]["qnty"]="$qnty";

part_no = varchar part number
po_id = varchar order number
weeky = week number
qnty = int quantity of items

I would like to retrieve the total number of qnty per part_no for each weeky

Please help!

thankyou in advance.

Maybe, foreach part_no get qnty and weeky....

Have you already tried count($datasq["$part_no"]) ?

Also, if $part_no is a number, there is no need for double quotation marks. You can just call it by numeric association.

thanks for the replies.
sorry dudes i may not have been clear and clarity is what i need!
the idea is that there may be 10 different part numbers and i need a cumulative count for each distinct part number.
so kinda...
foreach part number [distinct] get total quantity for week
it might just be easier to do this in sql.
This is starting to pickle my brain.

Let me see if i got this straight:

What you want to do is accumulate the weeky count for each week in all the part numbers? As to see how many parts per week you have?

Maybe you have already tried this or maybe I still do not understand your question, but I will post this anyway, you know, just in case...

foreach($datasq as $key=>$val){
  echo "For part no". $key. "<br />";
  echo "qnty is: ". $val['qnty'];
}

EDIT: @Nichito sorry mate. did not see that.

Thanks for posting.
The function returns the qnty for each item brilliantly. thankyou.
However, the count for each item needs to be cumulative.

eg.

part qnty
red 3
blue 2
red 16
orange 1
blue 90
blue 5

red = 19
blue = 97
orange = 1

i just cannot get my head around how to approach the problem.

Nichito

that is EXACTLY correct.

Even t point me in the right direction would be appreciated.
should i even be using arrays? or would an SQL query do the job?
Agghhh!

you can do this perfectly in php, though you'd have to create an array for the different weeky values. Better do this with a sql query, using sum(column) and a group by clause.

thanks Nichito

i was looking at trying to do it that way but the sql already involves an inner join.
thought arrays may be simpler. DOH!

I will post what i end up doing.

Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.