I have a table called payment which adds all the payment entries. I have field in payment table as customer_id which refers to the customer id in the customer table.
There is a field called flag where I store 1 or 0 based on their payment status. If they paid the full amount they flag will be 0 and if there is a balance the flag wil be 1
There is another field in payment table, added_on, which is a timestamp
I want to fetch out the latest added row of all the customer_id(in the payment table) who have flag 1(pending payment)
I tried fetching from the payment table like this
$rResult = mysql_query("select * from payment where flag='1'")
and then looped like this
while ($aRow=mysql_fetch_object($rResult))
{
//fetch out the customer id like this
$customer= $aRow->customer_id;
$pay_quer = mysql_query("select*from payment where customer_id='$customer'");
}
I know it is long to do this..is there any shorter way to do it with one query?
The results are not coming as I expected too. 🙁
or (it’s not clear what you want exactly nor how the flag is used). This will show different results, only those customers that their latest row in the
paymenthasflag=1: