-9

I have 2 questions:

  1. How can i select the data from the database where datetime>now() by writing php code?

  2. if there is the data from the database where datetime>now() , i want select the last two value from the database. what should i do?

I'm doing my gps tracking website. At the moment,my page is just select the last data to show the last position on the map. What i want is ,when i login my page, i will see the final position of the vehicle, and if the vehicles moves(mean the datetime of the data in database>now(), i want to select the 2 last updated data frequently to caculate the distance

JackABC
  • 27
  • 2
  • 7
  • 1
    please explain what you tried before. – Nad Sep 26 '14 at 12:38
  • Please give us an code example of what you've tried and problems you're having and we can help you better. – llanato Sep 26 '14 at 12:39
  • This is a simple question, with a very easy answer... But I (among others) will not answer until you do some research on your own. I can link to two other SO questions that answer each of yours. State what you have tried, at a minimum – Oberst Sep 26 '14 at 12:41
  • I'm doing my gps tracking website. At the moment,my page is just select the last data to show the last position on the map. What i want is ,when i login my page, i will see the final position of the vehicle, and if the vehicles moves(mean the datetime of the data in database>now(), i want to select the 2 last updated data frequently to caculate the distance – JackABC Sep 26 '14 at 13:00

2 Answers2

1
  1. Store now() in a variable and then compare using where clause.

Also see this and this

Update :<?php $timeZone = 'Asia/Kolkata'; //variable for indian timezone date_default_timezone_set( $timeZone); //default timezone set to indian time $now = date("m/d/y G.i:s"); echo $now; ?>

Check for date functions in PHP

Community
  • 1
  • 1
Ganesh Salunkhe
  • 596
  • 1
  • 4
  • 18
  • I write $now=now(); and then echo $now; but my page announce the now() function is undefined. What should i do – JackABC Sep 26 '14 at 13:13
1
$sql = "
    SELECT columnname 
    FROM tablename 
    WHERE DATE(yourdatefieldname) >= DATE(NOW())";

write this in if else

Tony
  • 9,672
  • 3
  • 47
  • 75
vicky bajpai
  • 45
  • 1
  • 4