Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

MySQL Count() question.. (mysql newb)

 
   Database Help (Home) -> PHP RSS
Next:  management scrips  
Author Message
knoak

External


Since: May 31, 2004
Posts: 4



(Msg. 1) Posted: Thu Feb 17, 2005 4:45 am
Post subject: MySQL Count() question.. (mysql newb)
Archived from groups: comp>lang>php (more info?)

Hi there,

I have a small question:
I have a table with lots of rows in it. Of course all have a different id,
but each can be assigned to a certain category. Categories correspond
with 1 - 10.

So a row looks like this: 'unique id | 4'

What i want is to do a count how much rows belong to a certain category.
Is it possible to do the following (from 1 query)

echo $counted_rows['4'];

Which sould return the number of rows with category '4';

Or is there anything similar if this is wrong?

Any help is great!! Smile

 >> Stay informed about: MySQL Count() question.. (mysql newb) 
Back to top
Login to vote
kevin97

External


Since: Dec 17, 2004
Posts: 2



(Msg. 2) Posted: Thu Feb 17, 2005 8:38 am
Post subject: Re: MySQL Count() question.. (mysql newb) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

To get the number of rows with a category '4' use:

SELECT COUNT( * ) FROM `table` WHERE category = '4';

To get the row count for all categories in a single query (I think what
you're asking for):

SELECT COUNT( category ) AS repetitions, category FROM `table`
GROUP BY category

- Kevin

"knoak" wrote in message

 > Hi there,
 >
 > I have a small question:
 > I have a table with lots of rows in it. Of course all have a different id,
 > but each can be assigned to a certain category. Categories correspond
 > with 1 - 10.
 >
 > So a row looks like this: 'unique id | 4'
 >
 > What i want is to do a count how much rows belong to a certain category.
 > Is it possible to do the following (from 1 query)
 >
 > echo $counted_rows['4'];
 >
 > Which sould return the number of rows with category '4';
 >
 > Or is there anything similar if this is wrong?
 >
 > Any help is great!! Smile

 >> Stay informed about: MySQL Count() question.. (mysql newb) 
Back to top
Login to vote
knoak

External


Since: May 31, 2004
Posts: 4



(Msg. 3) Posted: Thu Feb 17, 2005 11:37 am
Post subject: Re: MySQL Count() question.. (mysql newb) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Well, to begin: Thank you for helping. Very Happy

Ehm i know i am not asking for the first, because this would force me
to run the query for each category.

Could you please explain a little bit more about the second one? I can't seem
to get it to work... Sad :s

Thanks again



"Kevin" wrote in message ...
 > To get the number of rows with a category '4' use:
 >
 > SELECT COUNT( * ) FROM `table` WHERE category = '4';
 >
 > To get the row count for all categories in a single query (I think what
 > you're asking for):
 >
 > SELECT COUNT( category ) AS repetitions, category FROM `table`
 > GROUP BY category
 >
 > - Kevin
 >


  > > Hi there,
  > >
  > > I have a small question:
  > > I have a table with lots of rows in it. Of course all have a different id,
  > > but each can be assigned to a certain category. Categories correspond
  > > with 1 - 10.
  > >
  > > So a row looks like this: 'unique id | 4'
  > >
  > > What i want is to do a count how much rows belong to a certain category.
  > > Is it possible to do the following (from 1 query)
  > >
  > > echo $counted_rows['4'];
  > >
  > > Which sould return the number of rows with category '4';
  > >
  > > Or is there anything similar if this is wrong?
  > >
  > > Any help is great!! Smile
 >> Stay informed about: MySQL Count() question.. (mysql newb) 
Back to top
Login to vote
kevin97

External


Since: Dec 17, 2004
Posts: 2



(Msg. 4) Posted: Thu Feb 17, 2005 4:27 pm
Post subject: Re: MySQL Count() question.. (mysql newb) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

What problem are you having? Obviously you need to replace the field and
table names with the ones from your table.

"knoak" wrote in message

 > Well, to begin: Thank you for helping. Very Happy
 >
 > Ehm i know i am not asking for the first, because this would force me
 > to run the query for each category.
 >
 > Could you please explain a little bit more about the second one? I can't
 > seem
 > to get it to work... Sad :s
 >
 > Thanks again
 >
 >
 >


  >> To get the number of rows with a category '4' use:
  >>
  >> SELECT COUNT( * ) FROM `table` WHERE category = '4';
  >>
  >> To get the row count for all categories in a single query (I think what
  >> you're asking for):
  >>
  >> SELECT COUNT( category ) AS repetitions, category FROM `table`
  >> GROUP BY category
  >>
  >> - Kevin
  >>


   >> > Hi there,
   >> >
   >> > I have a small question:
   >> > I have a table with lots of rows in it. Of course all have a different
   >> > id,
   >> > but each can be assigned to a certain category. Categories correspond
   >> > with 1 - 10.
   >> >
   >> > So a row looks like this: 'unique id | 4'
   >> >
   >> > What i want is to do a count how much rows belong to a certain
   >> > category.
   >> > Is it possible to do the following (from 1 query)
   >> >
   >> > echo $counted_rows['4'];
   >> >
   >> > Which sould return the number of rows with category '4';
   >> >
   >> > Or is there anything similar if this is wrong?
   >> >
   >> > Any help is great!! Smile
 >> Stay informed about: MySQL Count() question.. (mysql newb) 
Back to top
Login to vote
knoak

External


Since: May 31, 2004
Posts: 4



(Msg. 5) Posted: Fri Feb 18, 2005 3:32 am
Post subject: Re: MySQL Count() question.. (mysql newb) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Yes thanks, that far i got, but how can i call the values in different parts
of the page, whereever i want.
So for instance i have 10 tables and in the first one i call $counted_rows_4
or so, and in the next one $counted_rows_9. So they correspond with the
category. It doesnt matter how i call them, as long as i can call them
individually.

Hope you get it, and sorry for me being a noob. I googled on this, searched the
mysql site, but couldn't find anything that makes sense to me.

Thanks again.




"Kevin" wrote in message ...
 > What problem are you having? Obviously you need to replace the field and
 > table names with the ones from your table.
 >


  > > Well, to begin: Thank you for helping. Very Happy
  > >
  > > Ehm i know i am not asking for the first, because this would force me
  > > to run the query for each category.
  > >
  > > Could you please explain a little bit more about the second one? I can't
  > > seem
  > > to get it to work... Sad :s
  > >
  > > Thanks again
  > >
  > >
  > >


   > >> To get the number of rows with a category '4' use:
   > >>
   > >> SELECT COUNT( * ) FROM `table` WHERE category = '4';
   > >>
   > >> To get the row count for all categories in a single query (I think what
   > >> you're asking for):
   > >>
   > >> SELECT COUNT( category ) AS repetitions, category FROM `table`
   > >> GROUP BY category
   > >>
   > >> - Kevin
   > >>


   > >> > Hi there,
   > >> >
   > >> > I have a small question:
   > >> > I have a table with lots of rows in it. Of course all have a different
   > >> > id,
   > >> > but each can be assigned to a certain category. Categories correspond
   > >> > with 1 - 10.
   > >> >
   > >> > So a row looks like this: 'unique id | 4'
   > >> >
   > >> > What i want is to do a count how much rows belong to a certain
   > >> > category.
   > >> > Is it possible to do the following (from 1 query)
   > >> >
   > >> > echo $counted_rows['4'];
   > >> >
   > >> > Which sould return the number of rows with category '4';
   > >> >
   > >> > Or is there anything similar if this is wrong?
   > >> >
   > >> > Any help is great!! Smile
 >> Stay informed about: MySQL Count() question.. (mysql newb) 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
using mysql count - I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php, I use: $query2 = "SELECT id, order_no, price, count(ite...

MySql count - The following snippet (for whatever reason) returns no value for the count. Suggestions? $arr = array ("A", "B", "C", "D", "E"); foreach ($arr as $client) { $count = mysql_query('SELECT COUNT(*) from ta...

How get skipped row count in PDO-MYSQL when use 'LOAD DATA.. - I use a PDO-MYSQL and executing a query like 'LOAD DATA INFILE ...'. If I execute this query with mysql_query() I can use mysql_info() to get info like "String format: Records: 42 Deleted: 0 Skipped: 5 Warnings: 0." How can I get this string ...

PHP saying error in mysql syntax, but written my mysql que.. - Hi, I have a basic db that I access with MySQL query browser. Everything seems fine to me but I am using this db as part of a php shopping basket and when I try to add an item I get: Notice: Query failed: You have an error in your SQL syntax; check the...

slow mysql "sending data" stage between mysql and php - Hello! I have problem: I have IPB forum installed. After search in IPB (search takes about 3-4 seconds for post table about 300 000 records) mysql shows "Sending Data" status and takes about 3-5 minutes. I tested with PHP 5.2, PHP 4.4, PHP 4....
   Database Help (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]