Jump to content

Archived

This topic is now archived and is closed to further replies.

monkeybidz

Calculating or adding a variable to itself

Recommended Posts

I have a variable $listing_fee. When $items_found = mysql_num_rows($result) give a result of more than one item, it creates a new row. Each row generates a $listing_fee for each item like it should. Each $listing_fee may be different. The problem here, is that the $listing_fee has the same name on each row, but i want to add(calculate the amounts. I cannot rename $listing_fee to $listing_fee1, $listing_fee2 and so on since the amount of rows may differ each time. does anyone know how i can make add $listing_fee + whatever other $listing_fee that may result?

Thanks in advance.

Hope you can understand what im trying to do. Oh!, almost forgot the amount that defines the $listing_fee does not come from mysql, it is passed from another page through include.

Share this post


Link to post
Share on other sites
why not do like select count(listing_fee) as total where ... ?

if not, then just use a 2nd variable

$x = 0;
while (fetch array)
$x = $x + $listing_fee;
}

Share this post


Link to post
Share on other sites
I have a query that selects users info and items purchased from mysql database and
creates a different row for each result. I added a variable $listing_fee to
the result row. So now each row "mysql_num_rows($result)" prints out something like this:

item number -- description -- fee
_____________________________________
123456 -- standard plan -- 1.00
1245 -- standard plan -- 1.00
321321 -- beyond plan -- 3.00
45646 -- second plan -- 2.50
458778 -- standard plan -- 1.00
----------------------------------------------------
The following variables represent the above each row.
$plan = description
$listing_fee = fee
----------------------------------------------------
Everything works fine and looks good. I get the number result
on each row like it should according to the plan and fee.
Below is some info that each row uses for each item. I am trying
to add(+) the rersults for each $listing_fee on each row to get a
$total_due. This is where the problem is. Each row variable is named
$listing_fee as it is created as many time of row result. So if the
customer purchased 20 plans, i will have 20 rows with different
price depending on the plan purchased. I need to add these together.

$standard_fee = 1.00;
$second_fee = 2.50;
$beyond_fee = 3.00;

if($plan == '1') {
$listing_fee = $standard_fee;
}

if($plan == '2') {
$listing_fee = $second_fee;
}

if($plan == '3') {
$listing_fee = $beyond_fee;
}

This is what i have done so far and gets me close to the total.


$total_due = mysql_num_rows($result)* $listing_fee;


This would work if all where priced the same.

"$listing _fee" is not mysql. Info is gathered from the same page or script.

Can someone help? The entire code is too long to post.

Share this post


Link to post
Share on other sites
Along the lines of the original reply:

<php>
if($plan == '1') {
$listing_fee = $standard_fee;
}

if($plan == '2') {
$listing_fee = $second_fee;
}

if($plan == '3') {
$listing_fee = $beyond_fee;
}

$total += $listing_fee;
</php>

Share this post


Link to post
Share on other sites
[img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /] [b]jajtiii[/b]
You got it!

I knew it could be done, i was just not explaining myself good enough.

Thanks so much.

Share this post


Link to post
Share on other sites

×

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.