CodeIgniter Forums
problem with where clause!!! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: problem with where clause!!! (/showthread.php?tid=38073)



problem with where clause!!! - El Forum - 01-29-2011

[eluser]immi[/eluser]
Hi

I am making a page which display videos on controller i added microtime(true) for table field 'lastwatch'. I want to grab the records on a page where lastwatch is lower than 300 seconds but it makes me error
Code:
function sqldiff($time){
    return $time - microtime(true);

}
$data["q"] = $this->db->query("SELECT * from vid_info where sqldiff(lastwatch)< 100 order by lwatch desc")->num_rows();


I get this error
Quote:A Database Error Occurred
Error Number: 1305

FUNCTION mujrahome.sqldiff does not exist

SELECT * from vid_info where sqldiff(lastwatch)<= 100 order by lwatch desc


KINDLY HELP!!!


problem with where clause!!! - El Forum - 01-29-2011

[eluser]JHackamack[/eluser]
You can't mix a PHP function with a mysql column. Take a look at MySQL Timestamp Diff:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timediff


problem with where clause!!! - El Forum - 01-29-2011

[eluser]immi[/eluser]
thanks! I have turned it different way like this

$value = microtime(true) - 2000;
$value = $this->db->escape($value);
$config['total_rows'] = $this->db->query("SELECT * from vid_info where lwatch > $value order by lwatch desc")->num_rows();


Thnx