I have the following table where some results of 'myvariable' are 1 and some not. I using this code in PHP:
$result=mysql_query("
SELECT COUNT(*) AS `total` FROM `mytable`
WHERE `myvariable`='1'
ORDER BY `id` DESC
LIMIT 15;"
);
$data=mysql_fetch_array($result);
$count = $data['total'];
echo $count;
As you see, I need to count (1+1+1+1)
and get final result of this 'myvariable' in mytable but only for the last 15 rows, not for full table.
How to do that?
Update, I can get this result:
myvariable:
1
0
1
1
1
0
0
0
0
1
0
0
0
1
0
But I don't need that. I need only ONE number and that number of myvariable in this case must be 6.
Calculating last 15 numbers give you this:
(1+0+1+1+1+0+0+0+0+1+0+0+0+1+0)=6
Only for last 15 rows not a result from whole table.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…