今天按日期筛选 Postgres 和 PHP


Filter by date today Postgres and PHP

目前是Postgres和php的新手 需要有关获取当前日期的帮助 要显示的树总数

我只需要计算当前日期的当前树,但似乎无法使其工作。

 $sql = "SELECT trees.tree_type, tree_solds.transaction_id, 
                tree_solds.actual_height, tree_solds.selling_height, 
                tree_solds.sub_total,transactions.date_purchased 
         FROM tree_solds
         LEFT JOIN trees on tree_solds.tree_id = trees.id
         LEFT JOIN transactions on transactions.id = tree_solds.transaction_id
         WHERE user_id = 8";
 $res = pg_query($sql);
 $count = pg_num_rows($res);
 echo $count;
我不知道

我是否明白问题出在哪里,但是既然您说"当前日期",我想您只是缺少按日期过滤?

 $sql = "SELECT trees.tree_type, tree_solds.transaction_id, 
            tree_solds.actual_height, tree_solds.selling_height, 
            tree_solds.sub_total,transactions.date_purchased 
     FROM tree_solds
     LEFT JOIN trees on tree_solds.tree_id = trees.id
     LEFT JOIN transactions on transactions.id = tree_solds.transaction_id
     WHERE user_id = 8 AND transactions.date_purchased BETWEEN current_date AND current_date + INTERVAL '1 DAY'";