|
-
Oct 28th, 2009, 03:33 AM
#41
Re: [RESOLVED] PHP Validator/Error checking
Post #39 is an example. You need to actually read what I wrote and apply it to your code.
-
Oct 28th, 2009, 03:37 AM
#42
Re: [RESOLVED] PHP Validator/Error checking
 Originally Posted by visualAd
Post #39 is an example. You need to actually read what I wrote and apply it to your code.
Sorry, I have added to my last post!
Edit:
It seems that the loop is not being triggered! I manual put the total in for the previous two rows and it works. However for some reason the loop only counts the final row in the table and not the rows before it. This is the code I'm using:
PHP Code:
for ($i=0; $i < $depth; $i++) { $item = $cart->get_item($i); $deleted = $item->deleted; if (!$deleted){ $item_id = $item->get_item_id(); $item_name = $item->get_item_name(); $qty = $item->get_qty(); $price = $item->get_price(); $total_amount = 170; $total_amount = $total_amount +($price*$qty); echo"<tr><td>$item_name</td><td>$qty </td><td>$price</td></tr>"; } }
The above code has the "$total_amount" variable set to the total of the first two rows I was using. The unedited code is here.
Last edited by Nightwalker83; Oct 28th, 2009 at 04:40 AM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Oct 28th, 2009, 06:15 PM
#43
Re: [RESOLVED] PHP Validator/Error checking
 Originally Posted by Nightwalker83
I have set it like so:
PHP Code:
$totalAmount = 0; $total_amount = $total_amount +($price*$qty);
Although, I still get the above message on the second line, I think it has to do with the second "$total_amount" rather than the first.
you initialised $totalAmount, but you're referring to $total_amount in the actual code. now, I don't know what else you're talking about here, so I'm going to just assume this will fix your initial problem!
like visualAd and I have been saying, you should be initialising your integer values as a ZERO. you don't initialise it as an equation. treat it like you would another language, if you must, by explicitly declaring every variable you're using at the top of your script:
PHP Code:
<?php //declarations $type = ''; $whatever = 0; $total_amount = 0;
//rest of my code goes here
-
Oct 28th, 2009, 06:54 PM
#44
Re: [RESOLVED] PHP Validator/Error checking
 Originally Posted by kows
PHP Code:
<?php //declarations $type = ''; $whatever = 0; $total_amount = 0;
//rest of my code goes here
Thanks! That worked Although, I'm a bit confused as to why the same code doesn't work when I put "var" in front of it (see post #38)?
Edit:
Reading the php manual var on its own is not a keyword unlike in a language such as Visual Basic.
Last edited by Nightwalker83; Oct 28th, 2009 at 07:51 PM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Oct 28th, 2009, 08:29 PM
#45
Re: [RESOLVED] PHP Validator/Error checking
the var keyword is for declaring/initialising variables within a class (although not within a method). however, the var keyword is deprecated in PHP5; you can use the public, private or protected keywords instead. this is all about object oriented programming and I'd assume is over your head at this point.
if you want to declare a variable outside of a class, you can just assign it a value. this isn't javascript :)
-
Oct 28th, 2009, 08:38 PM
#46
Re: [RESOLVED] PHP Validator/Error checking
 Originally Posted by kows
the var keyword is for declaring/initialising variables within a class (although not within a method). however, the var keyword is deprecated in PHP5; you can use the public, private or protected keywords instead. this is all about object oriented programming and I'd assume is over your head at this point.
Ah ok! That confirms what I read in the "cart.php" link to script posted in post #42. I have done a bit of OOP but I still struggle with stuff sometimes.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|