Jump to content

[SOLVED] Get total # of rows...


Recommended Posts

Hi,

My table looks something like this:

 

table1:

Name : abc

Id: 1

Group: a

Num: 1

---------------

table1:

Name : sds

Id: 3

Group: a

Num: 2

--------------

Name: bbc

Id: 2

Group: b

Num: 5

--------------

 

I am trying to get total number of rows that are in Group "a" and group "b". For example in group "a" there are 2 peoples and in group "b", 1 person. So how would you achieve this using a query? Inner join etc?

 

Regards...

Link to comment
Share on other sites

Hi,

My table looks something like this:

 

table1:

Name : abc

Id: 1

Group: a

Num: 1

---------------

table1:

Name : sds

Id: 3

Group: a

Num: 2

--------------

Name: bbc

Id: 2

Group: b

Num: 5

--------------

 

I am trying to get total number of rows that are in Group "a" and group "b". For example in group "a" there are 2 peoples and in group "b", 1 person. So how would you achieve this using a query? Inner join etc?

 

Regards...

 


SELECT * FROM table WHERE group = 'a';

$rowsa = myql_num_rows($results)

SELECT * FROM table WHERE group = 'b';

4rowsb = mysql_num_rows($results1)

Link to comment
Share on other sites

 

$sql = "SELECT * FROM table WHERE group = 'a'";
$resulta = mysql_query($sql,$con);
$rowsa = mysql_num_rows($resulta);

$sql= "SELECT * FROM table WHERE group = 'b'";
$resultb = mysql_query($sql,$con);
$rowsb = mysql_num_rows($resultb);

Link to comment
Share on other sites

Or using one query:

SELECT COUNT(*) FROM `table` GROUP BY `group`

 

Sorry if i wasn't clear, the group can be anything, that was just an example. I want a query like ex:

Count Number of Fields that are under the group 'group' (anything can be in this 'group' field)

Say in my table i have 20 different groups and there are 100 people in these groups, i wnat to know how many ppl are in each group. I want to accomplish this using one query only.

Regards..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.