Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
HELP, Count Input Field Entries
Old 04-14-2009, 09:02 AM HELP, Count Input Field Entries
Novice Talker

Posts: 11
Trades: 0
Code:
<?
$ct_qty = 0;
$subTotal = 0;
for ($i = 0; $i < $numItem; $i++) {
   extract($cartContent[$i]);
   $productUrl = "index.php?c=$cat_id&p=$pd_id";
   $subTotal += $pd_price * $ct_qty;
?>

<div class="cart-item">
<div class="item"><a href="<?php echo $_SERVER['PHP_SELF'] . "?action=delete&cid=$ct_id"; ?>"><img src="images/remove.png" alt=""></a><a href="<?php echo $productUrl; ?>"><?php echo $pd_name; ?></a></div>
<div class="item-price"><?php echo displayAmount($pd_price); ?></div>
<div class="item-quantity">
  <input maxlength="3" name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);" />
  <input name="hidCartId[]" type="hidden" value="<?php echo $ct_id; ?>" />
  <input name="hidProductId[]" type="hidden" value="<?php echo $pd_id; ?>" />
</div>
<div class="item-total"><?php echo displayAmount($pd_price * $ct_qty); ?></div>
</div>
Basically this generates items in a shopping cart. I want to count all of the qtys in the input field and then add them together to have a overall number of items.

Code:
<input maxlength="3" name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);" />
This is the line of code that the qty is entered into.

How would i do this, im kinda a noob with php.

Any help is much appreciated.
doh85 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-14-2009, 10:55 AM Re: HELP, Count Input Field Entries
Extreme Talker

Posts: 177
Trades: 0
I'm a little confused, but here it goes...

I'm not sure what exactly corresponds to item quantity, I believe it's $ct_qty?

Regardless, through the for loop I would just do something like....
PHP Code:
$total_qty .+ $ct_qty
which is equivalent to taking each cart quantity and adding it to a total quantity through each iteration of the for loop. Then when the for loop is over, you'll have the total number of items in $total_qty.

Hope this helps.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 04-14-2009, 12:52 PM Re: HELP, Count Input Field Entries
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
I think KB meant

PHP Code:
$total_qty += $ct_qty
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to HELP, Count Input Field Entries
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11604 seconds with 12 queries