I have 2 columns (there are more) in clients
table.
conn_date bill_date
=======================
2016-08-25 2016-09-04
2016-08-01 2016-09-03
2016-08-08 2016-09-01
2016-08-09 2016-09-01
Now I want to show all data if selected month is = (equal) or > greater then conn_date
. I can get selected month from html select tag eg : 1, 2, 9.
For that purpose, I am using following query but it's showing data less than conn_date
"SELECT cbp.advance_amount, cbp.bill_month, cbp.due_amount, cbp.pay_amount, c.is_active, c.client_id, c.user_id, c.address, c.contact_no, zone.zone_name, package.package_name, c.monthly_bill, c.bill_date FROM clients
AS c LEFT JOIN zone ON zone.zone_id = c.zone_id
LEFT JOIN package ON package.package_id = c.package_id
LEFT JOIN clients_pay_bill AS cbp ON cbp.client_id = c.client_id
WHERE c.uid = '$uid' AND c.is_active = 1
AND MONTH(c.conn_date) > $selected_month
Using print_r
SELECT cbp.advance_amount, cbp.bill_month, cbp.due_amount, cbp.pay_amount,
c.is_active, c.client_id, c.user_id, c.address, c.contact_no, zone.zone_name, package.package_name, c.monthly_bill, c.bill_date
FROM clients AS c
LEFT JOIN zone ON zone.zone_id = c.zone_id
LEFT JOIN package ON package.package_id = c.package_id
LEFT JOIN clients_pay_bill AS cbp ON cbp.client_id = c.client_id
WHERE c.uid = '6' AND c.is_active = 1
AND MONTH(c.conn_date) > 4 AND c.zone_id != ''
ORDER BY c.client_id DESC
Selected Month Image
Basically, I want to show data which is not less than conn_date of selected month
The mysql query for that is
SELECT * FROM clients WHERE MONTH(conn_date)<='".$selected_month."'
From the description of your problem, it sounds like you want:
select c.*
from clients c
where conn_date >= str_to_date(concat(date_format(now(), '%Y-%m'), '-01'))
This returns dates greater than the current time. If you want a particular month of a particular year:
select c.*
from clients c
where conn_date >= str_to_date(concat_ws('-', $year, $month, '01'))
I am not sure what your query does, because it uses several tables not mentioned in the question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.