I would like to do a show how many promotion code left function. I already find out how to query the latest promotion. now i would like to show the code how many left.
Now I have 2 table,
this is t1.
+--------------+--------------------------+----------------------+
| id | name | description |
+--------------+--------------------------+----------------------+
| 1 | GG | GG is good |
| 2 | ABC DEFG | ABC DDDDD |
| 3 | CCARD | Gooooo |
+--------------+--------------------------+----------------------+
this is t2
+---------+------------+-------------------+------------------+
| id | kaid | code | timestamp |
+---------+------------+-------------------+------------------+
| 1 | 2 | ZZZZAAAAA | 123456789 |
| 2 | 2 | AAAZZADWWW | 123344444 |
| 3 | 1 | ASFASDFFFF | 123333333 |
| 4 | 2 | HHHHHFDFG | 123222222 |
| 5 | 1 | ASDASDADDDD | 123111111 |
| 6 | 1 | AAAAAAAA | |
| 7 | 1 | DGDFGDSFG | |
+---------+------------+-------------------+------------------+
I query the latest user get promotion code like this
$querylist = mysql_query("SELECT t2.*,t1.name FROM t2,t1 where t1.id = t2.kaid ORDER BY t2.timestamp desc limit 5");
while($rowlist = mysql_fetch_row($querylist)) {
$idlist[] = $rowlist['id'];
$user_list_latest[] = $rowlist;
}
After I loop query, I will get the data like this
1. GG
2. ABC DEFG
3. GG
4. ABC DEFG
5. ABC DEFG
Then I would like to show the count like this. Hypothesis the count data is $countleft
1. GG (This promotion code only 2 left!)
2. ABC DEFG (This promotion code only 0 left!)
3. GG (This promotion code only 2 left!)
4. ABC DEFG (This promotion code only 0 left!)
5. ABC DEFG (This promotion code only 0 left!)
the number 2 and 0 is $countleft. the t2 timestamp is means the user get the valid promotion code time. so the timestamp empty means nobody get yet.