views:

89

answers:

2

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
+4  A: 

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.

banzaimonkey
i have tried a little but i still confuse for "qty:500"
klox
Try LIMIT http://php.about.com/od/mysqlcommands/g/Limit_sql.htm or WHERE http://php.about.com/od/mysqlcommands/g/select_where.htm, depending on your requirements. Maybe: `SELECT * FROM table_name WHERE qty = 500;` or `WHERE qty LIKE '%500';`
banzaimonkey
A: 

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';
Zane Edward Dockery