Using Timestap to show messages

Hello there,

I have a mysql database that has an arriving timestamp and a departing timestamp. How would i filter, using php, to get the name (also from the database) of the visitor if they current time is between the two timestamps?! and show a message if there is no current visitor?

Many thanks
maccaj51Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Lukasz ChmielewskiConnect With a Mentor Commented:
$sqlquery = "SELECT * FROM mytable WHERE UNIX_TIMESTAMP(NOW()) BETWEEN UNIX_TIMESTAMP(mydate1) AND UNIX_TIMESTAMP(mydate2) ";
$result = mysql_query($sqlquery) or die("wrong query");

if(mysql_num_rows($result) == 0){
   echo"no rows for you !";
}else{
   // here you would output the mysql_fetch_array or just inform that there are rows
   echo"here are the results: <br />";
   while($row = mysql_fetch_array($result)){
      echo"$row[myfield1], $row[myfield2]";
   }
}

Open in new window

0
 
KalpanCommented:
you can query the database using the following

$sqlquery = "SELECT * FROM `dt_tb` WHERE dt BETWEEN '2005-01-01' AND '2005-12-31' ";

$saResults = mysql_query($sqlquery);

while($obResults = mssql_fetch_row($saResults))
{
   echo $obResults[0]." ".$obResults[1]; // change the field/column as your db table
}


0
 
maccaj51Author Commented:
Im not 100% but i think you may have misunderstood... very sorry if im wrong.

But i need to see whether the current time is between any of the database entries arriving and departing time...
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Lukasz ChmielewskiCommented:
Haven't tested it but try like this (if you have dates in your db) - if a straight timestamp just use UNIX_TIMESTAMP(NOW())

$sqlquery = "SELECT * FROM mytable WHERE UNIX_TIMESTAMP(NOW()) BETWEEN UNIX_TIMESTAMP(mydate1) AND UNIX_TIMESTAMP(mydate2) ";
0
 
KalpanCommented:
please refer the following query

$sqlquery = "SELECT * FROM `dt_tb` WHERE ".$arr_time." <= CURTIME()  AND ".$dep_time." >=  CURTIME()";
0
 
maccaj51Author Commented:
hi Roads_Roads,

Your solution works great but how will i then make a different message if there are no returned results?

0
 
maccaj51Author Commented:
HERO!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.