0

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
3
  • 3
    If you have no knowledge for this, go and learn. You're not here to be spoonfed. Commented Jul 26, 2010 at 3:11
  • a) Sort in the database. Always. b) Make a small script that outputs the results. c) If you can't do b), read a PHP/SQL book. Commented Jul 26, 2010 at 3:13
  • Do you even understand the question? Commented Jul 26, 2010 at 3:18

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Try LIMIT php.about.com/od/mysqlcommands/g/Limit_sql.htm or WHERE 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';
0

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';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.