Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include record count in dropdown list

Status
Not open for further replies.

PeDa

Technical User
Oct 10, 2002
227
0
0
NL
My MySQL table contains a column Date and various other columns; there are about 5000 records, and Date can have one of about 20 values. I want to make dropdown list containing the various values of Date and the number of records containing this Date: something like
Code:
SELECT Date AS ThisDate, (COUNT(*) Date WHERE Date=ThisDate) FROM MyTable
 
echo() the count into the caption for the option element just as you probably already do for the name of the item.

The code you provided is the SQL query and nothing to do with actually sending the output to the page other than it returns the data you need.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
quote:
"echo() the count into the caption for the option element just as you probably already do for the name of the item.
The code you provided is the SQL query and nothing to do with actually sending the output to the page other than it returns the data you need."

I see now I was unclear. I know how to make the dropdown list as such. I am looking voor valid SQL to fill it (my pseudo-SQL doesn't work)
 
Aha!
You got a PHP answer because this IS the PHP forum, ... ... For MySQL you need the be in forum436 and we need a clue about the structure of the table(s), because you cannot back-reference a query variable like this;

"WHERE Date=ThisDate)";

in the same query.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
quote:
For MySQL you need the be in forum436: MySQL and we need a clue about the structure of the table(s)

OK; thank you; I will

Peter D
 
All you'll need to do is use GROUP BY and you should get the query you're looking for.

--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
quote:
All you'll need to do is use GROUP BY and you should get the query you're looking for.

Yes, thank you. I had discovered that, and have now got it werking.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top