Page 1 of 1

MYSQL

Posted: Fri Dec 12, 2008 10:36 am
by radium35
<?

//stats


$con2 = mysql_connect('localhost', 'leads', '1111111');
mysql_select_db ("leads");

$count=mysql_query(" SELECT leads, COUNT(*) affiliate_id WHERE '$afid' GROUP BY '$afid' ");

$totalleads = $row[affid];

mysql_close($con2);

?>

want to count how many of the same values are in column affiliate_id?

Re: MYSQL

Posted: Fri Dec 12, 2008 11:39 am
by jaoudestudios
Your query is completely wrong. I am unable to help because I am not 100% sure what you are trying to do. I would suggest researching your query a bit more.

Re: MYSQL

Posted: Fri Dec 12, 2008 11:48 am
by radium35
I want to count values in column "affiliate_id" those that are the same... for example count all that are 1 and all that are 2 etc.

Re: MYSQL

Posted: Fri Dec 12, 2008 11:57 am
by jaoudestudios
Can you post your database schema.

Re: MYSQL

Posted: Fri Dec 12, 2008 12:04 pm
by radium35
iam emailing to you

Re: MYSQL

Posted: Fri Dec 12, 2008 12:06 pm
by jaoudestudios
I would prefer if you posted it, so others can join in and it will help other developers in the future - just the structure is fine.

Re: MYSQL

Posted: Fri Dec 12, 2008 12:06 pm
by radium35
Image

Re: MYSQL

Posted: Fri Dec 12, 2008 12:10 pm
by jaoudestudios
SELECT leads, COUNT(*) affiliate_id WHERE '$afid' GROUP BY '$afid'
Is this what you want?

Code: Select all

SELECT COUNT(lead_id) as total, affiliate_id GROUP BY affiliate_id
I dont know why you have a WHERE?

Re: MYSQL

Posted: Fri Dec 12, 2008 12:12 pm
by radium35
yes i want to count how many of the same values are in column affiliate_id

how would I echo that out?

$result = ??

Re: MYSQL

Posted: Fri Dec 12, 2008 12:17 pm
by jaoudestudios
You need to learn the basics!

This might help...

Code: Select all

 
$mysql=mysql_query("SELECT COUNT(lead_id) as total, affiliate_id GROUP BY affiliate_id");
while ($r = mysql_fetch_assoc($mysql)) {
    echo $r['affiliate_id']." --- ".$r['total']."<br />"; // nb: <br> for W3C transitional or <br /> for W3C strict
}
 

Re: MYSQL

Posted: Fri Dec 12, 2008 12:24 pm
by radium35
:banghead:

all I want to do is count in table leads how many of the SAME $afid values are in affiliate_id. I am using this $afid as the value I would like to count

Re: MYSQL

Posted: Fri Dec 12, 2008 12:31 pm
by jaoudestudios
Oh I see.

This this should be it...

Code: Select all

 
SELECT COUNT(lead_id) as total WHERE affiliate_id = '$afid'
 

Re: MYSQL

Posted: Fri Dec 12, 2008 1:13 pm
by radium35
no, does not work :drunk:

Re: MYSQL

Posted: Fri Dec 12, 2008 1:49 pm
by novice4eva
With what you are posting, all you will get from us is what jaoudestudios has already given it to you.....
radium35 wrote::banghead:

all I want to do is count in table leads how many of the SAME $afid values are in affiliate_id. I am using this $afid as the value I would like to count
jaoudestudios wrote:Oh I see.

This this should be it...

Code: Select all

 
SELECT COUNT(lead_id) as total WHERE affiliate_id = '$afid'
 
well so he missed out the "FROM lead" portion, don't say i didn't bother checking what error popped out...anyways from what i've seen it's better doing this

Code: Select all

 
SELECT COUNT(lead_id) as total FROM leads WHERE affiliate_id = '$afid'
 
:nono:

Re: MYSQL

Posted: Fri Dec 12, 2008 5:51 pm
by jaoudestudios
Oh yes sorry I forgot the FROM - was running out the house when I wrote it - thanks novice4eva :)