Tutorial :how to counting from data array?



Question:

i have some data at DB like:

qty       item  id  date  0001-0500 abcd  1   2010-06-22  0001-0500 abcd  2   2010-06-22  0001-0500 abcd  3   2010-06-22  

i want some script can make them order by date and show result :

qty : 500 (it means 500-1=500,number 1 read 1-1 = 0)  item : abcd  id : 3 (counting from 1 until 3)  date :2010-06-22    qty    item     id   date  500    abcd     3     2010-06-22  

i have tried like this:

'SELECT qty, item, COUNT(*) FROM inspec GROUP BY date';  

before use the code above,i still confuse to make changes at :

qty         0001-0500   0001-0500      =>result become:qty : 500 (it means 500-1=500,number 1 read 1-1 = 0)  0001-0500  


Solution:1

Sorting and counting can be (and I'd say usually are) done at the database level, using SQL. Otherwise, there are language constructs that can do the heavy lifting for you, again, called sort and count.

If you're using MySQL, the tutorial is a good place to start learning. For PHP, you might find this book helpful.


Solution:2

i have tried like this:

'SELECT item, COUNT(*) FROM inspec GROUP BY date';  

If you want qty, shouldn't you SELECT it as well?

'SELECT item, COUNT(*), qty FROM inspec GROUP BY date';  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »