Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem displaying ONLY data from last one min old 1

Status
Not open for further replies.

Edward07

Programmer
Apr 13, 2007
49
NL
I am trying to display records from last one min onward using the following query:

Code:
res = mysql_query('SELECT * FROM album where date > "$timeout"') or die('<error>'.mysql_error().'</error>');

But unfortunetly it doesn't display those data within one min. It displays all the data!!
The date is stored like this 2007-04-17 11:44:35 in my mysql table. could any one look at the query that i use
and let me know what i am doing wrong?Thanks

date feild datatype:`date` datetime NOT NULL default '0000-00-00 00:00:00',


query used to insert data using Now():

$query = "INSERT INTO album (`ID`, `date`) VALUES ('$ID',NOW() )";

Date stored format:2007-04-17 11:44:35


Code:
<?php
header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
$server   = "localhost"; // MySQL hostname
$username = "root"; // MySQL username
$password = "root"; // MySQL password
$dbname   = "db"; // MySQL db name



$db = mysql_connect($server, $username, $password) or die(mysql_error());
      mysql_select_db($dbname) or die(mysql_error());

// this is necessary, otherwise it won't work: 
header('Content-type: application/xml'); 
// you need to return the error as xml as well 

$timeout = time() - 60; // number of seconds to keep users in database 

$res = mysql_query('SELECT * FROM album where date > "$timeout"') or die('<error>'.mysql_error().'</error>'); 
// display the root node of the xml, and start looping over the elements: 
echo '<playlist>'; 
while($row = mysql_fetch_assoc($res)){ 
  echo '<song>'; 
  echo '<artist>'.$row['albumname'].'</artist>'; 
  echo '</song>'; 
} 
echo '</playlist>';  


?>
 
you shouldn't be using php for this (or else you should be posting in the php forum)

Code:
SELECT * FROM album 
 where date >= date_sub(current_datetime, interval 1 minute)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top