Forum Moderators: coopster

Message Too Old, No Replies

Do I have too many variables?

         

doodlebee

6:30 pm on Feb 23, 2009 (gmt 0)

10+ Year Member



The issue here is that I have a question, but I don't know how to ask it. SO I'm thinking the answer is in the proper format of the question, rather than the actual answer itself.

Yes, very existential, I know LOL

I'll start with the code:


for($n=1;$n<=$attcount;$n++){
$attnames = 'attribute' . $n . '_value';
$attributes = get_post_meta($post->ID, $attnames, true);
$getall = explode("\r\n",$attributes);
$count = count($getall);

this works exactly as it needs to. $count properly pulls in the exact values I need.

My issue is this:

I need $count*$count - which I can't do just with that type of call because it'll just blow up in my face.

Basically, the values in the above piece of code are very dynamic. I use one form to set how many fields I need in a another form. So if - in the initial form - someone enters "3", then in the next form there are 3 input fields.

In each input field, you can have as many values as you like, separated by line breaks. So I need to count the values in each input field.

If there is only *one* input field, I just need $count. That's working fine - no problems at all.

However, if there's 2 or more input fields, I need the count for *each* field, and then I need to multiply the $count for *each* field by the other fields. So if there's 3 fields, and one field has 3 values, another has 6, and the last has 1, then I need something that is similar to:

$total = ($count1 * $count2 * $count3);

My issue is I can't seem to get form point a to point b. I'm looking for some piece of code that goes between "$count = count($getall);" and "$total = ($count1 * $count2 * $count3);".

Anyonehave ideas for me?

incrediBILL

8:47 pm on Mar 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Maybe I'm missing the problem but you either need an an array to store all the results or simple do the following in each pass of the loop:

$total = ($total * $count);

Just make sure to initialize $total to 1 before the loop otherwise your result will be 0