返回

php——我如何才能只获取今天的数据,并将数据数据库提取到api?

发布时间:2022-05-04 19:53:16 243
# redis# 数据库

我怎样才能得到今天的数据呢。 last_update这些是日期,应该会带来最新的数据。WHERE $ filter这些是安卓系统的条件。

datbase表

猫咪 最后更新
8 2022-03-12 08:59:17
8 2022-03-12 09:59:17
\`\` public function getRecentRecipes() {

            include "../includes/config.php";
            $setting_qry    = "SELECT * FROM tbl_settings where id = '1'";
            $setting_result = mysqli_query($connect, $setting_qry);
            $settings_row   = mysqli_fetch_assoc($setting_result);
            $api_key    = $settings_row['api_key'];
    
            if (isset($_GET['api_key'])) {
    
                $access_key_received = $_GET['api_key'];
                $filter = $_GET['filter'];
    
                if ($access_key_received == $api_key) {
    
                    if($this->get_request_method() != "GET") $this->response('',406);
                        $limit = isset($this->_request['count']) ? ((int)$this->_request['count']) : 10;
                        $page = isset($this->_request['page']) ? ((int)$this->_request['page']) : 1;
                        
                        $offset = ($page * $limit) - $limit;
                        $count_total = $this->get_count_result("SELECT COUNT(DISTINCT n.recipe_id) FROM tbl_recipes n WHERE $filter ");
                        $query = "SELECT DISTINCT n.recipe_id, 
                                    n.recipe_title, 
                                    n.cat_id,
                                    n.recipe_time, 
                                    n.recipe_image,
                                    n.last_update,
                                    n.recipe_description,
                                    n.video_url,
                                    n.video_id, 
                                    n.content_type,
                                    n.featured,
                                    n.tags,
                                    n.total_views,
                                    c.category_name,
                                    c.category_newsimage
                   
                                  FROM tbl_recipes n 
    
                                  LEFT JOIN tbl_category c ON n.cat_id = c.cid
    
                                  WHERE $filter
    
                                  GROUP BY n.recipe_id 
    
                                  ORDER BY n.recipe_id 
    
                                  DESC LIMIT $limit OFFSET $offset";
    
                        $posts = $this->get_list_result($query);
                        $count = count($posts);
                        $respon = array(
                            'status' => 'ok', 'count' => $count, 'count_total' => $count_total, 'pages' => $page, 'posts' => $posts
                        );
                        $this->response($this->json($respon), 200);
    
                } else {
                    $respon = array( 'status' => 'failed', 'message' => 'Oops, API Key is Incorrect!');
                    $this->response($this->json($respon), 404);
                }
            } else {
                $respon = array( 'status' => 'failed', 'message' => 'Forbidden, API Key is Required!');
                $this->response($this->json($respon), 404);
            }
    
    }`

`

我怎样才能得到今天的数据呢。上次更新这些是日期,应该会带来当前数据

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像