Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    I Need to update quantities on order when checkbox is present next to textbox

    I Need to update quantities on order when checkbox is present next to textbox, right now I have it populate the productCount variable from the database for the quantity, because alot of times all items will be going on a order.

    It works on a single entry, but I need to build the array to have it work with multiple items.

    THE POINT OF THE ADD: Is so the order number down on the bottom will get wrote to the value in the database. I can give you the structures of the 2 tables also if needed.

    I have it updating a single record, but need to update multiple values in a database where I have checkboxes present.

    I have included a screenshot.




    Theres a set of checkboxes on the right, in the ADD column. When this is clicked I need to take the number that is in the box to the right of it, and some how put it into an array, so when I insert that into the tables, it adjusts the quantities.

    My script all ready updates the quantities, but it takes the text box value from one of the textboxes, and uses that as the primary number since the text boxes are named the exact same thing.

    here is my existing page code.
    PHP Code:
    <?php
    session_start
    ();
    include 
    'dbc.php';
    include 
    'functions.php';
    if (!isset(
    $_SESSION['user']))
    {
    die (
    "Access Denied");
    }




    ?>



    <h2><b>Inventory</b> </h2>
    <?php if (isset($_SESSION['user'])) { ?>
    <p>Logged as <?php echo $_SESSION['user']; ?>
    | <a href="settings.php">Settings</a> | <a href="logout.php">Logout</a> </p>
      
    <?php
    //connect to database
    $sql="SELECT * FROM _products WHERE pending='1' ORDER BY productID ASC";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);
    ?>

    <link href="styles.css" rel="stylesheet" type="text/css">

    <center>



    <p>&nbsp;</p>

    <a href="inv_main.php">Main</a>
    <br>

    </p>
    <table width="700" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td>
    <table width="700" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <form name="form1" method="post" action="">
    <td height="52" colspan="10" bgcolor="#d5e8f9" class="mnuheader"><div align="center"><strong><br><h3>Pending</h3>
    </strong></div></td>
    </tr>

    <tr>
    <td bgcolor="#74889b" class="mnubody" align="center"><span class="style1">#</span></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><span class="style1">ID:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Number:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Desc:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Count # on hand</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Weight Each:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Customer:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Update:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">ADD:</span></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1"># to ADD:</span></td>
    </tr>


    <?php
    for($a$a mysql_num_rows($result); $a++)
    {
    $rows mysql_fetch_array($result);
    echo (
    $a == 0) ? '<tr>' '<tr class="altrow">' "\n";
    ?>  


    <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['productID']; ?>"></td>
    <td><? echo $rows['productID']; ?></td>
    <td><? echo $rows['productNum']; ?></td>  
    <td> <? echo $rows['productDesc']; ?></td>  
    <td><? echo $rows['productCount']; ?></td>
    <td><? echo $rows['weight']; ?></td>
    <td><? echo $rows['customer']; ?></td>  


    <td align="center"><a href="update.php?productID=<? echo $rows['productID']; ?>"><img src="images/interface/edit.png" border="0"/></a></td>
    <td align="center" bgcolor="#FFFFFF"><input name="addcheckbox[]" type="checkbox" id="addcheckbox[]" value="<? echo $rows['productID']; ?>"></td>
    <td align="center"><input name="numberAdded" type="text" id="numberAdded" size="5" value="<? echo $rows['productCount']; ?>"></td>
    </tr>  
    <?php
    }  
    ?>



    <?php
    }
    ?>
    <tr>
    <td colspan="2" align="center" bgcolor="#FFFFFF"><input name="remove" type="submit" id="remove" value="Remove From Pending"></td>

    <td colspan="3" align="center" bgcolor="#FFFFFF"></td>

    <td colspan="2" align="center" bgcolor="#FFFFFF"><?php showOrderList();?></td>
    <td colspan="3" align="center" bgcolor="#FFFFFF"><input name="add" type="submit" id="add" value="Add"> </td>

    </tr>
    <?php
    // Check if delete button active, start this
    if($remove){
    for(
    $i=0;$i<$count;$i++){
    $remove_id $checkbox[$i];

    $sql "UPDATE _products SET pending='0' WHERE productID='$remove_id'";   
    $result mysql_query($sql);
    }
    // if successful redirect to inv_main.php
    if($result)
    {
    echo 
    "<meta http-equiv=\"refresh\" content=\"0;URL=pending.php\">";
    }
    }


    // Check if add to order button is active
    if($add){
    for(
    $j=0;$j<$count;$j++){
    $add_id $addcheckbox[$j];




    $sql "UPDATE _products, _productsonorder SET _productsonorder.quantity=_productsonorder.quantity+$numberAdded,_products.productCount=_products.productCount-$numberAdded WHERE _products.productID=_productsonorder.productID
    AND _productsonorder.productID ='$add_id'"
    ;
    $addresult mysql_query($sql);
    }

    // if successful redirect page
    if($addresult){
    echo 
    "<meta http-equiv=\"refresh\" content=\"1;URL=pending.php\">";
    }
    }



    ?>
    </table>
    </form>
    </td>
    </tr>
    </table>

    <?php

    ?>

    </center>



    <?php
    mysql_close
    ();
    ?>

    and the part that handles seeing what checkbox in there is present is.

    PHP Code:
    // Check if add to order button is active
    if($add){
    for(
    $j=0;$j<$count;$j++){
    $add_id $addcheckbox[$j];




    $sql "UPDATE _products, _productsonorder SET _productsonorder.quantity=_productsonorder.quantity+$numberAdded,_products.productCount=_products.productCount-$numberAdded WHERE _products.productID=_productsonorder.productID
    AND _productsonorder.productID ='$add_id'"
    ;
    $addresult mysql_query($sql);
    }

    // if successful redirect page
    if($addresult){
    echo 
    "<meta http-equiv=\"refresh\" content=\"1;URL=pending.php\">";
    }


  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    I think the part about getting checkbox values is wrong ... I see no $_POST ...

    Make a safe copy of your existing script and replace the part with this ...

    PHP Code:
    // Check if add to order button is active 
    if($add){
    // Put all form checkbox values into an array...
    $checkboxes $_POST['addcheckbox']; 
    foreach (
    $checkboxes as $add_id) {

    $sql "UPDATE _products, _productsonorder SET _productsonorder.quantity=_productsonorder.quantity+$numberAdded,_products.productCount=_products.productCount-$numberAdded WHERE _products.productID=_productsonorder.productID 
    AND _productsonorder.productID ='$add_id'"

    $addresult mysql_query($sql); 


  • #3
    New Coder
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thats kind of what gets me. I know the checkbox part works.. because I flag these items as pending the exact same way.

    and it takes the values perfect.


    Its the part that was added the getting values from the text boxes that is not working.

    I guess I don't know how to create the array correctly for it maybe?


    just sucks this has turned into a multi forum, multi day error im trying to solve.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    It looks like you're doing the right thing with the checkboxes.
    You're assigning their value to the ID of the row ... that's good.

    Now, here's a thing about checkboxes.
    When you process the form with PHP, the checkboxes only exist if they are checked.
    That means, when you look at the checkbox array, you won't see any of the uncheck checkboxes.

    But for each checkbox that was checked, the array should contain the ID number.

    You now know the ID number for every line that was checked "ADD".

    So, how do you know how much to add? the "# to add" ?

    I think that's where you are stuck?

  • #5
    New Coder
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yes thats completely the issue.

    the id passes to the query with the right id numbers, but I need to tie the ___ checkbox to the right to the ID some how.

    I tried making the text box an array value also..

    heres a snippet of original

    PHP Code:
    <td align="center"><a href="update.php?productID=<? echo $rows['productID']; ?>"><img src="images/interface/edit.png" border="0"/></a></td>
    <td align="center" bgcolor="#FFFFFF"><input name="addcheckbox[]" type="checkbox" id="addcheckbox[]" value="<? echo $rows['productID']; ?>"></td>
    <td align="center"><input name="numberAdded" type="text" id="numberAdded" size="5" value="<? echo $rows['productCount']; ?>"></td>
    so shouldn't I be able to make the array of the numberAdded the same. But then its calling the value in the box, do I need another if statement checking those boxes also.

    I found this..
    http://www.webdeveloper.com/forum/sh...d.php?t=209752

    I dont know if that solves this issue? or if he has the same issue.

    because I need to put that text box value into an array, so it should be something like this.

    and heres what I was going to try with an array of it.

    PHP Code:
    <td align="center"><input name="numberAdded[]" type="text" id="numberAdded[]" size="5" value="<? echo $rows['productCount']; ?>"></td>
    I'm just foggy if i can use the id number of the checked box, but have that somehow tied to the textbox next to it? Right as it is now the text boxes are all named the same, so when it does the 2 table insert, it uses one of the boxes, kind-of randomly, I think the box that has the bigger value.


    I also found this which might help but I have an unknown # of items in the array depending on what items are flagged as pending.

    http://www.codingforums.com/showthread.php?t=200305

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    Let' pretend your form has 20 lines displayed ...

    If you make the "numberAdded[]" array, and you check 10 checkboxes,
    you'll have a "addcheckbox[]" array with 10 elements in it (only 10 were checked).
    That checkbox array would be addcheckbox[0], addcheckbox[1] .... addcheckbox[9]

    But ... But ... your numberAdded[] array will have 20 elements in it.

    Remember that PHP will only see the checkboxes that are checked (10 boxes).
    But your numberAdded[] array will have all 20 of the lines.

    That's why you're having a problem.
    You don't know which ID's match which numberAdded lines.

    =================

    Possible solution:

    You use an array for your "numberAdded[]" , but you add another thing to the value.

    Add the ID to the value by doing this:

    <td align="center"><input name="numberAdded[]" type="text" id="numberAdded[]" size="5" value="<? echo $rows['productID']."|".$rows['productCount']; ?>"></td>

    Now, when you process your form,
    cycle through your numberAdded array.
    explode it ... since they are separated by pipes |
    then loop through the checkbox array to see if that ID should be updated.

    Like this:
    PHP Code:
    foreach($numberAdded as $line){
    $items=explode("|",$line);
    // now you have  $items[0]=ID and $items[1]=the value
       
    // loop through the checkbox array to see if the ID should be added or not.
       
    foreach($addcheckbox as $check){
          if(
    $check == $items[0]){
          
    // they match, so update it
          // the value to add is $items[1]
          
    }
       }
    }
    ?> 

    Now remember that I'm just winging-it ... nothing tested.
    But this might lead you into some other ideas.


    .
    Last edited by mlseim; 08-24-2010 at 05:01 PM.

  • #7
    New Coder
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you for the great explanation.

    I guess now what I'm missing is what am I doing away with, with the current code thats there? if any.. or just adding this below the

    PHP Code:
    // Check if add to order button is active
    if($add){
    for(
    $j=0;$j<$count;$j++){
    $add_id $addcheckbox[$j]; 

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    Try the script below ... totally untested.

    Make a safe copy of your existing script before you overwrite it.

    PHP Code:
    <?php

    // Check if add to order button is active
    if($add){

    foreach(
    $numberAdded as $line){
    $items=explode("|",$line);
    // now you have  $items[0]=ID and $items[1]=the value
       
    // loop through the checkbox array to see if the ID should be added or not.
       
    foreach($addcheckbox as $check){
          if(
    $check == $items[0]){
          
    $sql "UPDATE _products, _productsonorder SET _productsonorder.quantity=_productsonorder.quantity+$items[1],_products.productCount=_products.productCount-$items[1] WHERE _products.productID=_productsonorder.productID AND _productsonorder.productID ='$items[0]'";
          
    $addresult mysql_query($sql);
          }
       }
    }

    // if successful redirect page
    if($addresult){
    echo 
    "<meta http-equiv=\"refresh\" content=\"1;URL=pending.php\">";
    }

    }

    ?>

    EDIT:
    I'm not sure if the $query string requires brackets around the array variables: {$items[1]}
    If there's a syntax error, that might be needed for those array variables?


    .
    Last edited by mlseim; 08-25-2010 at 04:35 PM.

  • #9
    New Coder
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It works amazing, now that we know that works, after all that process, is there a way to have it only show 106 which is the quantity available instead of, 2079|106 if possible. and still keep the 2079 as a hidden value? somehow.

    If not I'm 100% happy and great-full that it works!


    code im using now is,

    PHP Code:
    <?php
    session_start
    ();
    include 
    'dbc.php';
    include 
    'functions.php';
    if (!isset(
    $_SESSION['user']))
    {
    die (
    "Access Denied");
    }




    ?>



    <h2><b>Inventory</b> </h2>
    <?php if (isset($_SESSION['user'])) { ?>
    <p>Logged as <?php echo $_SESSION['user']; ?>
    | <a href="settings.php">Settings</a> | <a href="logout.php">Logout</a> </p>
      
    <?php
    //connect to database
    $sql="SELECT * FROM _products WHERE pending='1' ORDER BY productID ASC";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);
    ?>

    <link href="styles.css" rel="stylesheet" type="text/css">

    <center>



    <p>&nbsp;</p>

    <a href="inv_main.php">Main</a>
    <br>

    </p>
    <table width="700" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td>
    <table width="700" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <form name="form1" method="post" action="">
    <td height="52" colspan="10" bgcolor="#d5e8f9" class="mnuheader"><div align="center"><strong><br><h3>Pending</h3>
    </strong></div></td>
    </tr>

    <tr>
    <td bgcolor="#74889b" class="mnubody" align="center"><span class="style1">#</span></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><span class="style1">ID:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Number:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Desc:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Count # on hand</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Weight Each:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Customer:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Update:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">ADD:</span></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1"># to ADD:</span></td>
    </tr>


    <?php
    for($a$a mysql_num_rows($result); $a++)
    {
    $rows mysql_fetch_array($result);
    echo (
    $a == 0) ? '<tr>' '<tr class="altrow">' "\n";
    ?>  


    <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['productID']; ?>"></td>
    <td><? echo $rows['productID']; ?></td>
    <td><? echo $rows['productNum']; ?></td>  
    <td> <? echo $rows['productDesc']; ?></td>  
    <td><? echo $rows['productCount']; ?></td>
    <td><? echo $rows['weight']; ?></td>
    <td><? echo $rows['customer']; ?></td>  


    <td align="center"><a href="update.php?productID=<? echo $rows['productID']; ?>"><img src="images/interface/edit.png" border="0"/></a></td>
    <td align="center" bgcolor="#FFFFFF"><input name="addcheckbox[]" type="checkbox" id="addcheckbox[]" value="<? echo $rows['productID']; ?>"></td>
    <td align="center"><input name="numberAdded[]" type="text" id="numberAdded[]" size="5" value="<? echo $rows['productID']."|".$rows['productCount']; ?>"></td>
    </tr>  
    <?php
    }  
    ?>



    <?php
    }
    ?>
    <tr>
    <td colspan="2" align="center" bgcolor="#FFFFFF"><input name="remove" type="submit" id="remove" value="Remove From Pending"></td>

    <td colspan="3" align="center" bgcolor="#FFFFFF"></td>

    <td colspan="2" align="center" bgcolor="#FFFFFF"><?php showOrderList();?></td>
    <td colspan="3" align="center" bgcolor="#FFFFFF"><input name="add" type="submit" id="add" value="Add"> </td>

    </tr>
    <?php
    // Check if delete button active, start this
    if($remove){
    for(
    $i=0;$i<$count;$i++){
    $remove_id $checkbox[$i];

    $sql "UPDATE _products SET pending='0' WHERE productID='$remove_id'";   
    $result mysql_query($sql);
    }
    // if successful redirect to inv_main.php
    if($result)
    {
    echo 
    "<meta http-equiv=\"refresh\" content=\"0;URL=pending.php\">";
    }
    }


    // Check if add to order button is active
    if($add){

    foreach(
    $numberAdded as $line){
    $items=explode("|",$line);
    // now you have  $items[0]=ID and $items[1]=the value
       
    // loop through the checkbox array to see if the ID should be added or not.
       
    foreach($addcheckbox as $check){
          if(
    $check == $items[0]){
          
    $sql "UPDATE _products, _productsonorder SET _productsonorder.quantity=_productsonorder.quantity+$items[1],_products.productCount=_products.productCount-$items[1] WHERE _products.productID=_productsonorder.productID AND _productsonorder.productID ='$items[0]'";
          
    $addresult mysql_query($sql);
          }
       }
    }

    // if successful redirect page
    if($addresult){
    echo 
    "<meta http-equiv=\"refresh\" content=\"1;URL=pending.php\">";
    }

    }



    ?>
    </table>
    </form>
    </td>
    </tr>
    </table>

    <?php

    ?>

    </center>



    <?php
    mysql_close
    ();
    ?>

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    doh!

    You are right, I didn't even think of that.

    .... let me ponder it a moment ...



    .

  • #11
    New Coder
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts
    NO I mean in the actual box.

    see below.





    thanks for all the help..

  • #12
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    I had an idea ...
    But it won't work ... still thinking.

  • #13
    New Coder
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts
    you replied so fast I didn't catch it..

    LOL looks like the code update you posted.. wiped the available quantity out.

    let me look at it and see what might be different.

  • #14
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    That idea I had was flawed ..
    I'm getting close to trying something ...

  • #15
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    I think I got it now ...

    Make a safe copy of the original before you try this:
    Copy the whole thing, as I made changes in various places.

    PHP Code:
    <?php
    session_start
    ();
    include 
    'dbc.php';
    include 
    'functions.php';
    if (!isset(
    $_SESSION['user']))
    {
    die (
    "Access Denied");
    }




    ?>



    <h2><b>Inventory</b> </h2>
    <?php if (isset($_SESSION['user'])) { ?>
    <p>Logged as <?php echo $_SESSION['user']; ?>
    | <a href="settings.php">Settings</a> | <a href="logout.php">Logout</a> </p>
      
    <?php
    //connect to database
    $sql="SELECT * FROM _products WHERE pending='1' ORDER BY productID ASC";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);
    ?>

    <link href="styles.css" rel="stylesheet" type="text/css">

    <center>



    <p>&nbsp;</p>

    <a href="inv_main.php">Main</a>
    <br>

    </p>
    <table width="700" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td>
    <table width="700" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <form name="form1" method="post" action="">
    <td height="52" colspan="10" bgcolor="#d5e8f9" class="mnuheader"><div align="center"><strong><br><h3>Pending</h3>
    </strong></div></td>
    </tr>

    <tr>
    <td bgcolor="#74889b" class="mnubody" align="center"><span class="style1">#</span></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><span class="style1">ID:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Number:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Desc:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Count # on hand</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Weight Each:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Customer:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Update:</strong></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">ADD:</span></td>
    <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1"># to ADD:</span></td>
    </tr>


    <?php
    $i
    =0;
    for(
    $a$a mysql_num_rows($result); $a++)
    {
    $rows mysql_fetch_array($result);
    echo (
    $a == 0) ? '<tr>' '<tr class="altrow">' "\n";
    ?>  


    <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['productID']; ?>"></td>
    <td><? echo $rows['productID']; ?></td>
    <td><? echo $rows['productNum']; ?></td>  
    <td> <? echo $rows['productDesc']; ?></td>  
    <td><? echo $rows['productCount']; ?></td>
    <td><? echo $rows['weight']; ?></td>
    <td><? echo $rows['customer']; ?></td>  


    <td align="center"><a href="update.php?productID=<? echo $rows['productID']; ?>"><img src="images/interface/edit.png" border="0"/></a></td>
    <td align="center" bgcolor="#FFFFFF"><input name="addcheckbox[]" type="checkbox" id="addcheckbox[]" value="<? echo $rows['productID']."|".$i?>"></td>
    <td align="center"><input name="numberAdded[]" type="text" id="numberAdded[]" size="5" value="<? echo $rows['productCount']; ?>"></td>
    </tr>  
    <?php
    $i
    ++
    }  
    ?>



    <?php
    }
    ?>
    <tr>
    <td colspan="2" align="center" bgcolor="#FFFFFF"><input name="remove" type="submit" id="remove" value="Remove From Pending"></td>

    <td colspan="3" align="center" bgcolor="#FFFFFF"></td>

    <td colspan="2" align="center" bgcolor="#FFFFFF"><?php showOrderList();?></td>
    <td colspan="3" align="center" bgcolor="#FFFFFF"><input name="add" type="submit" id="add" value="Add"> </td>

    </tr>
    <?php
    // Check if delete button active, start this
    if($remove){
    for(
    $i=0;$i<$count;$i++){
    $remove_id $checkbox[$i];

    $sql "UPDATE _products SET pending='0' WHERE productID='$remove_id'";   
    $result mysql_query($sql);
    }
    // if successful redirect to inv_main.php
    if($result)
    {
    echo 
    "<meta http-equiv=\"refresh\" content=\"0;URL=pending.php\">";
    }
    }

    // Check if add to order button is active
    if($add){
       
    // loop through the checkbox array to see if the ID should be added or not.
       
    foreach($addcheckbox as $check){
          
    $items=explode("|",$check);
          
    // now we have ID and index number
            // $items[0] = ID  $items[1] = index
            
    $id=$items[0];
            
    $index=$items[1];
            
    $amount=$numberAdded[$index];
            
    $sql "UPDATE _products, _productsonorder SET _productsonorder.quantity=_productsonorder.quantity+$amount,_products.productCount=_products.productCount-$amount WHERE _products.productID=_productsonorder.productID AND _productsonorder.productID ='$id'";
            
    $addresult mysql_query($sql);
       }


    // if successful redirect page
    if($addresult){
    echo 
    "<meta http-equiv=\"refresh\" content=\"1;URL=pending.php\">";
    }

    }



    ?>
    </table>
    </form>
    </td>
    </tr>
    </table>

    <?php

    ?>

    </center>



    <?php
    mysql_close
    ();
    ?>

    I am putting an index number with the checkbox value ID|index
    That tells us which checkbox it is (the row in the array).

    See if that works better.



    .


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •