Currently new to Postgres and php Need help on getting current date total of trees to show
I just need to count current trees on current date but can’t seem to make it work.
JavaScript
x
$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;
Advertisement
Answer
I don’t know if I understand what is the problem, but since you say “current date” I guess you are just missing a filter by date?
JavaScript
$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'";