Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Timestap to show messages

Posted on 2011-02-16
7
Medium Priority
?
276 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:maccaj51
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:Kalpan
ID: 34905717
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
 

Author Comment

by:maccaj51
ID: 34905732
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
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34905771
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:Kalpan
ID: 34905784
please refer the following query

$sqlquery = "SELECT * FROM `dt_tb` WHERE ".$arr_time." <= CURTIME()  AND ".$dep_time." >=  CURTIME()";
0
 

Author Comment

by:maccaj51
ID: 34905868
hi Roads_Roads,

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

0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 34906084
$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
 

Author Closing Comment

by:maccaj51
ID: 34906103
HERO!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question