shibbir ahmed shibbir ahmed - 3 months ago 10
MySQL Question

How can I show data which is greater than or equal to mysql table column month?

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 e. g. : 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

enter image description here

Answer

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."'