This is a discussion on "Counting Instances in a table." within the Databases section. This forum, and the thread "Counting Instances in a table. are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Counting Instances in a table.
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Say I have a table something like this
I would rather avoid several queries and then having to count each row with php, or doing a single query then counting the whole thing in a loop >.> I searched threw the reference manual and couldn't find anything to help me, but I'm almost dead sure their is a way to do this. Please help >.< |
|
|
|
#2
|
|||
|
|||
|
Re: Counting Instances in a table.
Found a solution that almost gives me what I want. And is close enough that I can work with it
|
|
#3
|
|||
|
|||
|
Re: Counting Instances in a table.
Your solution is a good one, although I would count(ID) to count the number of non-NULL values in that particular column rather than counting all columns. I don't know of any way to transpose rows and columns in the results, and I do a lot of MySQL stuff!
Quote:
One that users can SEE, rather than one that gets squished by a ******ing advert from Google. Such a signature can help the reader of the thread follow up a little bit more about the questioner and person who answers him so that he can judge the quality and background of the original post and reply, and it gives at least a little something back to the person who gives his time for free to answer, in the form of a short ad. </rant> -- Graham OOooo --- errrrr - looks like it might have seen my rant on this thread Last edited by grahame; Mar 18th, 2006 at 09:12. |
|
#4
|
|||
|
|||
|
Re: Counting Instances in a table.
Quote:
|
|
#5
|
|||
|
|||
|
Re: Counting Instances in a table.
Slight increase in speed perhaps ... but the reason I do it by a particular field in other is that it gives you the flexibility to count only rows which actually have a value in the column specified. If you count a column declared as NOT NULL you get everything, of course.
Example of the extra flexibility select agent, count(price), from hfs group by agent; will count up the number of properties for which a price is advertised, by agent. Probably not relevant though, if you're not going to want thie extra flexibility later. -- Graham |
|
#6
|
|||
|
|||
|
Re: Counting Instances in a table.
Not realy, but I will keep it in mind if I do need it.
Its for a game I work on, the table contains all units on a map, and I needed to know how many of each type of unit at a specific location there was. |
|
#7
|
|||
|
|||
|
Re: Counting Instances in a table.
Argh online rts games
|
![]() |
| Tags |
| counting, instances, table |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Prevent multiple instances of web page | duncanwill | JavaScript Forum | 2 | May 21st, 2008 08:16 |
| Internet Explorer not displaying some CSS in some instances! | DeveloperHanson | Web Page Design | 2 | Apr 22nd, 2008 12:19 |
| [need help-SEO]Counting no. of backlinks | RohanShenoy | Search Engine Optimization (SEO) | 6 | Feb 25th, 2008 06:51 |
| PHP XML Counting Elements | Don Logan | PHP Forum | 1 | Mar 18th, 2006 03:03 |
| Counting RecordSets.... | courtjester | Classic ASP | 5 | Aug 29th, 2004 08:44 |