CCF Hosting
12-28-2003, 02:32 PM
Hello,
I am trying to modify a script that will insert a timestamp into a mySQL database and then read it on every cron run to see if x hours has passed.
Here is my dilemma. I am pretty sure I can have mySQL insert it automatically. What would I use to read and it judge based on the amount of time passed. And if x hours has passed, then run another command?
I am pretty new at this, so all and any help is appreciated!
Thanks and God Bless!
UH-Matt
12-28-2003, 02:34 PM
Why post the same thing twice?
http://www.webhostingtalk.com/showthread.php?s=&threadid=220421
CCF Hosting
12-28-2003, 02:41 PM
I realized that there was a programming forum. So I posted in here instead. I have requested the mods to remove my other thread.
Thanks and God Bless!
Perhaps i misunderstood but it would just be a little simple math.
1. Get the time from the DB
2. Get the current time
3. Subtract 1 from 2 to get the difference
Then
if ($difference < x) {
echo "x amount of time has passed":
}
else {
echo "x amount of time has not passed";
}
x being the number of hours you want to allow.
Sorry if that doesn't make sense.
CCF Hosting
12-28-2003, 06:04 PM
Hello,
Ok. I have most of the code written. However, I am at a stand still. I am getting the message Resource id #3.
I am pretty sure I know why, but can't figure out how to fix it.
Here is my DB code:
$result = mysql_query("SELECT pack_order FROM package_type") or die("Query failed: " . mysql_error());
echo $result;
What am I missing? It is connecting and everything just fine. Just get that one message.
Thanks and God Bless!
Homeblock
12-28-2003, 09:26 PM
http://www.weberdev.com/get_example.php3/addcommentinterface.php3?count=3001
You want the bottom function. Just comment everything in the function out except hours. Then call the function with the database Timestamp and the current timestamp.
It will return the difference in hours.
kneuf
12-28-2003, 09:36 PM
CCF Hosting, try this:
$result_db = mysql_query("SELECT pack_order FROM package_type") or die("Query failed: " . mysql_error());
$result = mysql_result($result_db,0);
echo $result;
just typed it in there, should work ;)
check out: www.php.net/mysql_result
CCF Hosting
12-28-2003, 10:25 PM
Homeblock:
Here is what I am using for the UNIX Timestamp.
$then = $result; // your unix timestamp stored in MySQL
$now = time(); // current time stamp
$difference = $now - $then; // in seconds
/$difference = $difference / 3600 ; // devide difference in seconds by 1 hour in seconds
if ($difference < 24) {
echo "Yep!" . $difference;
}
else {
echo "Nope! Greater then 24" . $difference . "<br>";
That good? Or is it too complicated for my uses?
kneuf:
Thanks for you reply. I have something similar to that.
$result = mysql_query("SELECT pack_order FROM package_type") or die("Query failed: " . mysql_error());
$row = mysql_fetch_array($result);
$data = $row['pack_order'];
echo $data;
However, mine is less effecient and bulkier. Both methods seem to only pickup the first line of data. The script will need to read all lines, then cross-referrance it with another table in the database to see if the same Pack ID exists.
The only way I can get it to read all lines, is use this:
$result = mysql_query("SELECT pack_order FROM package_type") or die("Query failed: " . mysql_error());
$row = mysql_fetch_array($result);
//$data = $row['pack_order'];
//echo $data;
while ($row =
$pack_order = mysql_fetch_array($result))
{
printf ("Package Order: %s", $row["pack_order"] . "<br><br>");
}
//$pack_order = mysql_result($result,*);
//echo $pack_order;
mysql_free_result($result);
However, I don't know how to feed it into the script and have it anyalize it. Like place it in a variable.
Any ideas on this?
Thanks and God Bless!