X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=inc%2Fdb%2Fmysql.php;h=8e3fcf85394d618b97c7d1bbd4e68e8ee7abf859;hp=8fa49d52b68730a1a7edf980a18692e67cb06b6a;hb=e4a4e5149d55cf01a86f26392c52fdca803654ce;hpb=de485fbe85dc15d416ed08a51d6561fc8db0e078 diff --git a/inc/db/mysql.php b/inc/db/mysql.php index 8fa49d5..8e3fcf8 100644 --- a/inc/db/mysql.php +++ b/inc/db/mysql.php @@ -120,7 +120,7 @@ class mysqlConnection implements anydbConnection { $id = mysql_insert_id (); return new feature ($id, $feature->lon, $feature->lat, $feature->imgpath, $feature->title, - $feature->description); + $feature->description, $feature->date); } } @@ -134,7 +134,8 @@ class mysqlConnection implements anydbConnection { public function getfeature ($id) { $query = sprintf ("SELECT id, imgpath, title, description, AsText(location) - AS location FROM %sitems WHERE id = '%s';", + AS location, UNIX_TIMESTAMP(date) AS date FROM %sitems + WHERE id = '%s';", $this->dbprefix, mysql_real_escape_string ($id)); $row = mysql_fetch_assoc ($this->_execute_query ($query)); if ($row === false) { @@ -145,7 +146,7 @@ class mysqlConnection implements anydbConnection { public function listfeatures () { $query = sprintf ("SELECT id, imgpath, title, description, AsText(location) - AS location FROM %sitems;", + AS location, UNIX_TIMESTAMP(date) AS date FROM %sitems;", $this->dbprefix); $features = array (); @@ -159,6 +160,25 @@ class mysqlConnection implements anydbConnection { return $features; } + public function mostrecentfeatures ($num_features) { + $query = sprintf ("SELECT id, imgpath, title, description, + AsText(location) AS location, UNIX_TIMESTAMP(date) + AS date FROM %sitems ORDER BY date DESC", + $this->dbprefix); + if ($num_features) { + $query .= sprintf (" LIMIT %d", $num_features); + } + $features = array (); + $res = $this->_execute_query ($query); + while ($row = mysql_fetch_assoc ($res)) { + $feature = $this->_feature_frow_row ($row); + if (isset ($feature)) { + $features[] = $feature; + } + } + return $features; + } + public function imgpath_exists ($imgpath) { $query = sprintf ("SELECT COUNT(*) FROM %sitems WHERE imgpath LIKE '%s';", $this->dbprefix, mysql_real_escape_string ($imgpath)); @@ -226,7 +246,8 @@ class mysqlConnection implements anydbConnection { $lat = $matches [2]; try { $feature = new feature ($row ["id"], $lon, $lat, $row ["imgpath"], - $row ["title"], $row ["description"]); + $row ["title"], $row ["description"], + $row ["date"]); } catch (Exception $e) { return null; }