SELECT tb_customer.customer_id, tb_customer.customer_name, tb_payment.payment_date FROM tb_customer LEFT JOIN tb_payment ON tb_customer.customer_id = tb_payment.payment_customer_id AND tb_payment.payment_date LIKE '2013-04%' WHERE tb_payment.payment_date IS NULL
การนำไปใช้งาน ให้ค้นหาตามค่าเดือนปีที่ส่งมาจากฟอร์มค้นหา
<?php $sql = "SELECT tb_customer.customer_id, tb_customer.customer_name, tb_payment.payment_date "; $sql.= "FROM tb_customer "; $sql.= "LEFT JOIN tb_payment ON tb_customer.customer_id = tb_payment.payment_customer_id AND tb_payment.payment_date LIKE '". $_POST['year_month'] ."%'"; $sql.= "WHERE tb_payment.payment_date IS NULL"; $result = mysql_query($sql) or die(mysql_error()); while($rs = mysql_fetch_assoc($result)){ //CODE HERE... } ?>
ความคิดเห็น
แสดงความคิดเห็น