This topic is locked

Sum in this type of query possible?

1/20/2009 7:44:04 PM
PHPRunner General questions
C
chaintm author

error getting is...
=======================================

PHP error happened Technical information

Error type 256

Error description You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and event_time_end>=' at line 2

URL 192.168.1.100/moonjump/order_items_add.php?

Error file D:\vhosts\mj4u\output\include\dbconnection.php

Error line 34

SQL query select sum(Qty_Order) from event_times where Order_ID!=44 and event_time_start<= and event_time_end>=

Solution This is a general error. It occurs when there is an error in event code or in SQL.
===================================================================
{

$str1 = "select event_time_start,event_time_end,Qty_Order from event_times where Order_ID=".$_SESSION[$strTableName."_masterkey1"];

$rsh1 = db_query($str1,$conn);

while ($data1= db_fetch_array($rsh1))
$strSelect = "select event_time_start,event_time_end,Qty_Order from event_times where Order_ID!=".$_SESSION[$strTableName."_masterkey1"]."

and event_time_start<=".$data1["event_time_start"]." and event_time_end>=".$data1["event_time_start"];

$rsSelect = db_query($strSelect,$conn);
$strSelect1 = "select sum(Qty_Order) from event_times where Order_ID!=".$_SESSION[$strTableName."_masterkey1"]."

and event_time_start<=".$data1["event_time_start"]." and event_time_end>=".$data1["event_time_start"];

$rsSelect1 = db_query($strSelect1,$conn);

$data2 = db_fetch_array($rsSelect1);

{

if ($dataSelect = db_fetch_array($rsSelect) && $data1["Qty_Order"] >= $data2["Qty_Order"])

{

//echo ($rsSelect);

//echo ($rsh1);

echo "<font color=red><big><b>ITEM RESERVED FOR SAME DATE ON ANOTHER ORDER</b></big></font>, please select another item or goto list to edit current";

return false;
================================================
Now mind you before some go off on this, the code works fine when eliminating the questionable sum of Qty_Order, my guess is that because I am using the ! command to nulify a specifc order_id being used is my problem. Without the sum ofcourse it all works, but I need to add all feilds that fall within the given timestamps and values.
Any thoughts from anyone and ofcourse the admins would be great!
Thnx,
Noel

C
chaintm author 1/21/2009

thinking on this further, could it be a simple syntax issue?

J
Jane 1/21/2009

Noel,
Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

C
chaintm author 1/21/2009

Noel,

Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.


ok I cleaned up the security issues that my company doesn't want released and gave you in email direct links and login/pass to ftp , the project is very large.
Noel

C
chaintm author 1/21/2009

oh my bad jane,
I forgot to mention this code is in the order_items page and the menu system issue is order_sales . Sorry about that. Also I notice my text error above with $rsSelect not being $rsSelect1 but eh, it errored out prior, so I usually troubleshoot and finish the code as I go. If it is not seen what I am doing in all of that.
The times/dates are checked along with the sum total vs the total of item being order to see if the item being checked within all orders within the dates/times given is sum then ofcourse comparing that sum to the total of the item being order to make sure it doesn't exceed any orders for those given dates/times that are between or equal to the current order. Hope that makes sense, I think once you read threw the code you will see what I mean.
Please note I know I have more code to add elswhere to finish this whole process, but for some reason the sum wasn't working, it did once, then stopped and i changed nothing. So begin double guessing my own work. Looking forward to your thoughts.
Noel

C
chaintm author 1/21/2009

I figured this out, for those that know stuff and want to know what I did see below...
//============ query ItemID from order_items table to see if duplicate ItemID ==========//

$str6 = "select ItemID from order_items where Order_num=".$_SESSION[$strTableName."_masterkey1"]." and ItemID=".$values["ItemID"];

$rs6 = db_query($str6,$conn);

if ($data6 = db_fetch_array($rs6))

{

echo "<font color=red><big><b>DUPLICATE ITEM</b></big></font> for this order, please select another item or goto list to edit current";

return false;

}

else

//============ query from order_items table for Order_num if ItemID exisist in another order then continue ========//

{

$str3 = "select ItemID from order_items where ItemID=".$values["ItemID"];

$rs3 = db_query($str3,$conn);

}

if ($data3 = db_fetch_array($rs3))

//=====================================query from event_times for dates/inventory avaliblity=============================//

{

$str3 = "select sum(Qty_Order) as total_qty from event_times where Order_ID!=".$_SESSION[$strTableName."_masterkey1"]." and Item_ID=".$values["ItemID"];

$hrs3 = db_query($str3,$conn);

$rs3 = db_fetch_array($hrs3,$conn);

$data3 = $rs3['total_qty'];
$str5 = "select sum(ItemStockPhys) as total_qty2 from items where ItemID=".$values["ItemID"];

$hrs5 = db_query($str5,$conn);

$rs5 = db_fetch_array($hrs5,$conn);

$data5 = $rs5['total_qty2'];

$data6["temp_total"] = ($values["Qty_order"]+$data3["Qty_Order"])-1;
$str1 = "select event_time_start,event_time_end from event_times where Order_ID=".$_SESSION[$strTableName."_masterkey1"];

$rsh1 = db_query($str1,$conn);

while ($data1= db_fetch_array($rsh1))
$strSelect = "select * from event_times where Order_ID!=".$_SESSION[$strTableName."_masterkey1"]."

and Item_ID=".$values["ItemID"]." and event_time_start<=".$data1["event_time_start"]." and event_time_end>=".$data1["event_time_start"]."

and ".$data6["temp_total"]." >= ".$data5["ItemStockPhys"];
$rsSelect = db_query($strSelect,$conn);
{

if ($dataSelect = db_fetch_array($rsSelect))