I have two tables.
User
table has user_id and order_num
Orders
table has order_num, dd, mm, yyyy, order_detail.
When a user wants to see all orders for a certain month I usually select order_num from user table where user_id matches a cookie, then while loop and within the loop do a select on orders table matching order_num and displaying if month matches month selected.
Is there a more efficient way to do this? With a join of some sort? Quite basic sql knowledge but keen to expand
So, I currently do (i know its not good code but logical sql most important part of this question, i know how to code correctly)
select order_num from user where user_id = $cookie
while (results) {
select order_detail, mm, dd, yyyy where mm = $month
echo order_detail mm dd yyyy
}