Insert only date where month is not previous month
Hi...
I have codes in uploading .xml file to my database table, now I only need to save or insert only the data where ETD (Month from Date) is not previous Month.
ETD = date
Actually it's my first time to encounter this and while I'm posting this issue in forums., I also tried to find the answer.
here is my code:
PHP Code:
<?php
error_reporting(E_ALL ^ E_NOTICE);
date_default_timezone_set("Asia/Singapore"); //set the time zone
$data = array();
foreach( $cells as $cell )
{
$ind = $cell->getAttribute( 'Index' );
if ( $ind != null ) $index = $ind;
if ( $index == 1 ) $ETD = $cell->nodeValue;
if ( $index == 2 ) $PO_No = $cell->nodeValue;
if ( $index == 3 ) $SKUCode = $cell->nodeValue;
if ( $index == 4 ) $Description = $cell->nodeValue;
if ( $index == 5 ) $POReq = $cell->nodeValue;
if ( $index == 6 ) $Comp = $cell->nodeValue;
$index += 1;
}
if ($ETD=='' AND $PO_No=='' AND $SKUCode=='' AND $Description=='' AND $POReq=='' AND $Comp=='') {
$last_row = true;
}
else {
add_employee($ETD,$PO_No,$SKUCode,$Description, $POReq, $Comp);
}
}
if ($last_row==true) {
$first_row = true;
}
else {
$first_row = false;
}
}
}
?>
I tried this query:
Code:
$sql = "INSERT INTO sales_order (ETD,PO_No,SKUCode,Description,POReq,Comp)
VALUES
('$ETD','$PO_No','$SKUCode','$Description','$POReq','$Comp')
WHERE $ETD_month != '$date_now'" or die(mysql_error());
but still he get date where ETD(month from date) = March.
That way you only execute the query if the 2 months are different. You can refine the comparison condition depending on how the $EDT_month is generated.
Are you trying to saving data from months previous to the current month or just last month?
The comparison should be the full date (year-month-day) instead of just the month. It gives you more accurate results.
By the way where does the $ETD_month comes from.
If $EDT is a full date then just compare that whole date with the current one using the same format (e.g Y-m-d)
Is $ETD_month = 03 04 05 06 07 08 the whole sequence of these numbers?
If yes, then just have:
$EDT_months=explode(' ', $EDT_month) to convert it into an array.
Then
if(!in_array($date_now,$EDT_months)){
$sql="......"
....
}
Are you trying to saving data from months previous to the current month or just last month?
The comparison should be the full date (year-month-day) instead of just the month. It gives you more accurate results.
By the way where does the $ETD_month comes from.
If $EDT is a full date then just compare that whole date with the current one using the same format (e.g Y-m-d)
I'm trying to save data from the current month to the last month. I dont want to save data from the previous month which in my data is march.
why should the comparison is (Y-m-d)?
$EDT is a full date and $ETD_month is a variable where I only get the month from $ETD.
Is $ETD_month = 03 04 05 06 07 08 the whole sequence of these numbers?
If yes, then just have:
$EDT_months=explode(' ', $EDT_month) to convert it into an array.
Then
if(!in_array($date_now,$EDT_months)){
$sql="......"
....
}
I tried your suggested code:
PHP Code:
<?php
//ini_set('display_errors', -1);
//error_reporting(E_ALL);
//error_reporting(-1);
//error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL ^ E_NOTICE);
date_default_timezone_set("Asia/Singapore"); //set the time zone
$data = array();
foreach( $cells as $cell )
{
$ind = $cell->getAttribute( 'Index' );
if ( $ind != null ) $index = $ind;
/*if ( $index == 5 ) $ETD = $cell->nodeValue;
if ( $index == 18 ) $PO_No = $cell->nodeValue;
if ( $index == 23 ) $SKUCode = $cell->nodeValue;
if ( $index == 24 ) $Description = $cell->nodeValue;
if ( $index == 48 ) $POReq = $cell->nodeValue;
if ( $index == 28 ) $Comp = $cell->nodeValue;
if ( $index == 29 ) $Cloth = $cell->nodeValue; */
if ( $index == 1 ) $ETD = $cell->nodeValue;
if ( $index == 2 ) $PO_No = $cell->nodeValue;
if ( $index == 3 ) $SKUCode = $cell->nodeValue;
if ( $index == 4 ) $Description = $cell->nodeValue;
if ( $index == 5 ) $POReq = $cell->nodeValue;
if ( $index == 6 ) $Comp = $cell->nodeValue;
$index += 1;
}
if ($ETD=='' AND $PO_No=='' AND $SKUCode=='' AND $Description=='' AND $POReq=='' AND $Comp=='') {
$last_row = true;
}
else {
add_employee($ETD,$PO_No,$SKUCode,$Description, $POReq, $Comp);
}
}
if ($last_row==true) {
$first_row = true;
}
else {
$first_row = false;
}
}
}
$sql = "UPDATE sales_order s SET
CompKg = (SELECT Bch_Wt FROM param_settings p WHERE s.Comp = p.Compounds ORDER BY p.Compounds)";
$res = mysql_query($sql, $con);
?>
but it did not save.
the output of $ETD_month actually is:
ArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArray ArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArray ArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArray and so on.....
Bookmarks