This topic is locked

works great with numbers, but not with dates..

11/15/2008 8:02:12 PM
PHPRunner General questions
C
chaintm author

summary of issue:::
How do I convert datetime from mysql to php as intengers for a query without manipulating any database information

==========================================================
Everything below works great if I don't have the event_time_start and event_time_end fields in date format,

as soon as I do it errors out. So I know all my code works now, just not sure how to get the system to read

the dates without physically changing anything on the database. I just want it to read the dates in integers

(12321414553) then as dates, basicly I need to convert. **
PLEASE NOTE I am not calling any dates

from any user input, these dates are being pulled from item numbers and referanced to the dates. So no

date inputs or displays are being done here, just for the query aspect. See full code for understanding.

The code below is an exsert of what part is the issue...below that is all the code... I have looked all over

online and on php.net., a bunch of stuff on converting too dates but not from a date to integer just to

read it in a formula.
global $strTableName;

global $conn;

$str2 = "select event_time_start,event_time_end from order_sales where Order_num!=".$_SESSION[$strTableName."_masterkey1"];

$rsh2 = db_query($str2,$conn);
while ($data2= db_fetch_array($rsh2))
$str1 = "select event_time_start,event_time_end from order_sales where Order_num=".$_SESSION[$strTableName."_masterkey1"];

$rsh1 = db_query($str1,$conn);
while ($data1 = db_fetch_array($rsh1))
$strSelect = "select event_time_start,event_time_end from order_sales where Order_num!=".$_SESSION[$strTableName."_masterkey1"]." and event_time_start<=".$data1["event_time_start"]." and event_time_end>=".$data1["event_time_start"];

$rsSelect = db_query($strSelect,$conn);

{

if ($dataSelect = db_fetch_array($rsSelect))
[codebox]//=============== carry over values from other tables ===========//

$str = "select ItemRentalPrice,ItemThumb from items where ItemID='".$values["ItemID"]."'";

$rs = CustomQuery($str);

$data = db_fetch_array($rs);

$values ['ItemRentalPrice'] = $data['ItemRentalPrice'];

$values ['ItemThumb'] = $data['ItemThumb'];

$values["Sub_total"] = $values["Qty_order"]
$values["ItemRentalPrice"]1;$_SESSION["ItemThumb"] = $data["ItemThumb"];

$_SESSION["ItemRentalPrice"] = $data["ItemRentalPrice"];

//============== global ======================//

global $strTableName;

//============ query ItemID from order_items table to see if duplicate ItemID ==========//

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

global $conn;

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

{

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 ========//

{

global $strTableName;

global $conn;

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

$rs = db_query($str,$conn);

}

if ($data = db_fetch_array($rs))

//=====================================query from order_sales table for dates================================//

{

global $strTableName;

global $conn;

$str2 = "select event_time_start,event_time_end from order_sales where Order_num!=".$_SESSION[$strTableName."_masterkey1"];

$rsh2 = db_query($str2,$conn);
while ($data2= db_fetch_array($rsh2))
$str1 = "select event_time_start,event_time_end from order_sales where Order_num=".$_SESSION[$strTableName."_masterkey1"];

$rsh1 = db_query($str1,$conn);
while ($data1 = db_fetch_array($rsh1))
$strSelect = "select event_time_start,event_time_end from order_sales where Order_num!=".$_SESSION[$strTableName."_masterkey1"]." and event_time_start<=".$data1["event_time_start"]." and event_time_end>=".$data1["event_time_start"];

$rsSelect = db_query($strSelect,$conn);

{

if ($dataSelect = db_fetch_array($rsSelect))

//if ($data1["event_time_start"]=$data2["event_time_start"])// && $data1["event_time_start"]<=$data2["event_time_end"])

//|| $data1["event_time_end"]>=$data2["event_time_start"] && $data1["event_time_end"]<=$data2["event_time_end"]

//|| $data1["event_time_start"]<=$data2["event_time_start"] && $data1["event_time_end"]>=$data2["event_time_end"])

//if (strtotime($values["StartDateField"])-strtotime($values["EndDateField"])<0)

//if ($dataSelect = db_fetch_array($rsSelect))

{

echo "// //";

echo ($data1);

echo "// //";

echo ($dataSelect);

echo "// //";

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

return false;

}

}

}

//else

return true;[/codebox]

C
chaintm author 11/16/2008

Well I fixed it,
all I did was add
$values["event_time_start"] = strtotime($values["event_time_start"]);

$values["event_time_end"] = strtotime($values["event_time_end"]);
return true;
to my add and edit pages of my sales and then added
if ($value)

$value = date("m/d/Y",$value);
to my views and now I am working within the UNIX TIMESTAMP to solve the issue, for those looking for a good tracking system the above code works great, if you need more insight let me know, but this system basicly tracks items and their dates as orders are entered and if an order is entered that has an item in track on the same date and times (think rental system) then it says item in use.
Thnx all for the help and definitly thanx to the admin team!