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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Voting System Help 2

Status
Not open for further replies.

perlone

Programmer
May 20, 2001
438
US
Hello,

I'm creating a voting system and I was wondering if you could help me. I have 2 columns - gid,IP. `gid` is the ID for game and `IP` is for IP Address.

gid | IP
6 |xx.xxx.xx
7 |xx.xxx.xx
6 |xx.xxx.xx
6 |xx.xxx.xx

I want to display the results like this:

GID | Votes
6 | 3
7 | 1

As you can see, it counts how many votes each has. Does anyone knows how to do this? Thank You.
 
Given a table foo containing:

Code:
+------+---------+
| gid  | ip      |
+------+---------+
|    6 | 1.2.3.4 |
|    7 | 2.3.4.5 |
|    6 | 3.4.5.6 |
|    6 | 4.5.6.7 |
+------+---------+


The query

select gid, count(gid) as votes from foo group by gid;

will return:

Code:
+------+-------+
| gid  | votes |
+------+-------+
|    6 |     3 |
|    7 |     1 |
+------+-------+


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Hi,

I'm using phpMyAdmin and what 'type' of feld do you think IP address should hold? So far I have 'TEXT'. Is this ok? Thanks.
 
Depends on what you'll be using it for. Most likely though, is that you'd want it to be varchar(15).

//Daniel
 
Thank You. I was thinking about varchar(15) too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top