View Single Post
Old 08-30-2005, 03:41 PM   #6 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 136
metazai is on a distinguished road
oops . . .

You are absolutely right, and I apologize . . . I should know better.

Hopefully it's a little clearer below. The problem I have is this -- sending an item through with two descriptive variables (such as size and color), the item being sent survives the first check for no items matching part, session, or either variable, and if there are none, it executes perfectly.

PHP Code:

// pull all temp_orders with same session and item number; get total of existing items with same item_number; set case


$total_exis_items 0;
$query_pre =
  
"SELECT item_number,quantity,sessionid,variableone,variabletwo FROM temp_orders WHERE sessionid='$cust_session' AND item_number='$cust_item_number'";
$result_pre mysql_db_query($dbname$query_pre);
while (
$row_pre mysql_fetch_array($result_pre))
{
  
$total_exis_items = ($row_pre['quantity'] + $total_exis_items);
}


// check for no items matching (therefore new item entered into the order)


if ($total_exis_items == 0)

======
EXTERNAL FUNCTION THAT GIVES ME $cust_orderprice======== 

{
  
$query5 =
    
"INSERT temp_orders SET item_name='$cust_item_name', quantity='$cust_quantity', item_number='$cust_item_number', orderprice='$cust_orderprice', variableone='$cust_variableone', variabletwo='$cust_variabletwo', pricetype='$cust_pricetype', sessionid='$cust_session'";
  
mysql_query($query5)or die(mysql_error());
  echo(
    
"<meta http-equiv=\"refresh\" content=\"0;URL=../cart/display_cart.php\">");

Next, if the items match part, session AND BOTH variables, it again executes perfectly, adding the items to the existing quantity and adjusting the price accordingly:

PHP Code:

else


// pull items from temp_orders again for use on the next two checks


{
  
$query_ninety =
    
"SELECT item_number,quantity,sessionid,variableone,variabletwo FROM temp_orders WHERE sessionid='$cust_session' AND item_number='$cust_item_number'";
  
$result_ninety mysql_db_query($dbname$query_ninety);
  while (
$row_ninety mysql_fetch_array($result_ninety))
  {
    
$ravvarone $row_ninety['variableone'];
    
$ravvartwo $row_ninety['variabletwo'];


    
// check for matching items with both variables matching, if true, insert and adjust all prices that match the product number


    
if ($ravvarone $cust_variableone && $ravvartwo $cust_variabletwo)
    {

======
EXTERNAL FUNCTION THAT GIVES ME $cust_orderprice======== 

      
$final_exis_items = ($total_exis_items $cust_quantity);
      
$updated_quantity = ($row_ninety['quantity'] + $cust_quantity);
      
$query6 =
        
"UPDATE temp_orders SET orderprice='$cust_orderprice', quantity='$updated_quantity' WHERE sessionid='$cust_session' AND item_number='$ravvarone' AND variableone='$ravvartwo' AND variabletwo='$cust_variabletwo'";
      
mysql_query($query6)or die(mysql_error());
      
$querysix =
        
"UPDATE temp_orders SET orderprice='$cust_orderprice' WHERE sessionid='$cust_session' AND item_number='$cust_item_number'";
      
mysql_query($querysix)or die(mysql_error());
      echo(
        
"<meta http-equiv=\"refresh\" content=\"0;URL=../cart/display_cart.php\">");
    } 
Lastly, here is where it screws up. It never seems to even look at this code, preferring to run the last chunk even when $ravvarone does not equal $cust_variableone and/or $ravvartwo does not equal $cust_variabletwo):
PHP Code:


    
else


    
// assume variables don't match, i.e, enter a new product line on temp orders but adjust all prices that match the product number


    
{
      
$final_exis_items = ($total_exis_items $cust_quantity);

======
EXTERNAL FUNCTION THAT GIVES ME $new_orderprice======== 

     
$query5 =
        
"INSERT temp_orders SET item_name='$cust_item_name', quantity='$cust_quantity', item_number='$cust_item_number', orderprice='$new_orderprice', variableone='$ravvarone', variabletwo='$ravvartwo', pricetype='$cust_pricetype', sessionid='$cust_session'";
      
mysql_query($query5)or die(mysql_error());
      
$queryextra3 =
        
"UPDATE temp_orders SET orderprice='$new_orderprice' WHERE sessionid='$cust_session' AND item_number='$cust_item_number'";
      
mysql_query($queryextra3)or die(mysql_error());
      echo(
$query5."<br><br>".$queryextra3);
      
//echo("<meta http-equiv=\"refresh\" content=\"0;URL=../cart/display_cart.php\">");
    
}
  }
}

?> 
Hope that helps. Feel free to blow this one off if I haven't been clear enough, I don't want anyone to waste as much time as I have!

=+O
metazai is offline   Reply With Quote