monkeybidz Posted May 24, 2006 Share Posted May 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10308-calculating-or-adding-a-variable-to-itself/ Share on other sites More sharing options...
.josh Posted May 24, 2006 Share Posted May 24, 2006 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;} Quote Link to comment https://forums.phpfreaks.com/topic/10308-calculating-or-adding-a-variable-to-itself/#findComment-38440 Share on other sites More sharing options...
monkeybidz Posted May 27, 2006 Author Share Posted May 27, 2006 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.001245 -- standard plan -- 1.00321321 -- beyond plan -- 3.0045646 -- second plan -- 2.50458778 -- 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. Quote Link to comment https://forums.phpfreaks.com/topic/10308-calculating-or-adding-a-variable-to-itself/#findComment-39357 Share on other sites More sharing options...
jajtiii Posted May 27, 2006 Share Posted May 27, 2006 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> Quote Link to comment https://forums.phpfreaks.com/topic/10308-calculating-or-adding-a-variable-to-itself/#findComment-39367 Share on other sites More sharing options...
monkeybidz Posted May 27, 2006 Author Share Posted May 27, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/10308-calculating-or-adding-a-variable-to-itself/#findComment-39368 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.