PHP from database and query

Posted by Kyle R on Stack Overflow See other posts from Stack Overflow or by Kyle R
Published on 2011-01-09T11:34:27Z Indexed on 2011/01/09 11:53 UTC
Read the original article Hit count: 129

Filed under:
|
|

I have a table:

id, affiliate

Each time somebody clicks a link, a new row is inserted,

ID being the ID of the page, and affiliate being the ID of the affiliate.

For example:

Page ID: 9 Affiliate ID: 1

Page ID: 9 Affiliate ID: 2

Page ID: 9 Affiliate ID: 3

I only have 3 affiliates.

I want to select this information, and group them by affiliate, for the ID.

I have tried this query:

SELECT COUNT(*) FROM table WHERE id = '9' GROUP BY affiliate

It works fine when I do it in php my admin, how do I get the info in PHP?

I have tried:

$q = mysql_query("SELECT COUNT(*) FROM table WHERE id = '" . $id . "' GROUP BY affiliate");

$r = mysql_fetch_array($q);

When trying to print the data onto the page, I am only getting one result.

Do I need to use a foreach/while loop to get all 3? How would I go about doing this?

Thank you!

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql