...

View Full Version : I Need to update quantities on order when checkbox is present next to textbox



mnewbegin
08-23-2010, 08:49 PM
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.

http://www.consolidatedwarehouse.com/inventory/pending-for-order.jpg


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
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 % 2 == 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.pr oductCount-$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.



// 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.pr oductCount-$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\">";
}
}

mlseim
08-23-2010, 09:43 PM
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 ...



// 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.pr oductCount-$numberAdded WHERE _products.productID=_productsonorder.productID
AND _productsonorder.productID ='$add_id'";
$addresult = mysql_query($sql);
}

mnewbegin
08-24-2010, 04:33 AM
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.

mlseim
08-24-2010, 02:40 PM
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?

mnewbegin
08-24-2010, 04:14 PM
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



<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/showthread.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.



<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

mlseim
08-24-2010, 04:57 PM
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:


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.


.

mnewbegin
08-25-2010, 03:43 PM
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



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

mlseim
08-25-2010, 04:32 PM
Try the script below ... totally untested.

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



<?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?


.

mnewbegin
08-25-2010, 05:16 PM
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
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 % 2 == 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();
?>

mlseim
08-25-2010, 05:55 PM
doh!

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

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



.

mnewbegin
08-25-2010, 06:02 PM
NO I mean in the actual box.

see below.


http://www.consolidatedwarehouse.com/inventory/pending-for-order2.jpg


thanks for all the help..

mlseim
08-25-2010, 06:04 PM
I had an idea ...
But it won't work ... still thinking.

mnewbegin
08-25-2010, 06:05 PM
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.

mlseim
08-25-2010, 06:19 PM
That idea I had was flawed ..
I'm getting close to trying something ...

mlseim
08-25-2010, 07:30 PM
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
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 % 2 == 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.product Count-$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.



.

mnewbegin
08-25-2010, 07:42 PM
when I made this change it looks as if it works.


CHANGED FROM YOUR CODE


<?php
$i++;
?>



<?php
}
?>



YOUR CODE WAS THIS: it said unexpected } so i removed it and replaced with ;



<?php
$i++
}
?>



<?php
}
?>



and it seems to be GOLDEN!!!

thanks... ill test a little more.. but that is 1 big hurdle I can jump over for getting this done...

mlseim
08-25-2010, 08:05 PM
I make typos all the time :(

PHP form checkbox arrays ... whew

I realize why they do it the way to do ... they only return "checked" checkboxes
with a value, whether it's an array or not. If they also returned "unchecked" checkboxes,
there would be no way to define a value, unless they made the value "empty".

A value of empty would show up as "" ... but it would be "true" for isset().

As it stands now, unchecked boxes are not returned at all, so they show "false" for isset().

I would rather have unchecked boxes return as "empty", than not returned at all.

oh well.

mnewbegin
09-02-2010, 06:59 PM
Lol next issue.

I have the page with a small tweak to write to my 2 tables.

_products and _productsonorder.



$sql = "UPDATE _products, _productsonorder SET _productsonorder.quantity=_productsonorder.quantity+$amount,_productsonorder.orderNum='$ordernumber' ,_products.productCount=_products.productCount-$amount WHERE _products.productID=_productsonorder.productID AND _productsonorder.productID ='$id'";
$addresult = mysql_query($sql);

It writes to the 2 tables, and everything works great, but theres a drop down below, with a order number.

That order number replaces the order number on the _productsonorder table

BUT THE ISSUE WITH THAT IS IF I ADD A PRODUCT TO 1 ORDER AND THE SAME PRODUCT TO ANOTHER ORDER, I HAVE NO WAY TO DIFFERENTIATE THEM BETWEEN 2 ORDERS DOING THIS. THE NEW ORDER NUMBER REPLACES THE OLD ORDER NUMBER STORED THERE.

What do you think my best plan of action is? NOT UPDATE THE TABLE, AND JUST DO AN INSERT? and have the same items inserted tons of times.


There has to be a way to tell this, to update the quantity on the order.

mlseim
09-02-2010, 11:56 PM
I guess I don't understand the question ...

Do you have some kind of form we can see?
"drop down below" ... ??? not sure what that means either?

mnewbegin
09-23-2010, 03:40 PM
OK, I'm back on this project now, again.

Here is a screenshot of the process.

and a little info.


I add an item to an order by clicking a drop down at the bottom of the main screen, with the order number. In this case... the 1000007, or 1000008 and choosing a quantity and clicking the checkbox on the right.

Where my issue is. I add the SAME item to ANOTHER order, and it replaces the order number in the database.

http://www.consolidatedwarehouse.com/orderprocess.jpg

mlseim
09-26-2010, 03:07 AM
You have a table with a list of items.
You only have one field for order number, so it can only show the "last" number used.

To fix this, you need a table with a list of items, like you have ...
And a table with a list of orders, by order number.

ID | Order Number | Item ordered | QTY | Date |

You can remove the "orderNum" column from your item table,
as you won't need that ... it doesn't mean anything.

By having the new table, you can now search by order number,
and get a list of everything ordered under that number.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum