MYSQL
Moderator: General Moderators
MYSQL
<?
//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?
//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?
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: MYSQL
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
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.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: MYSQL
Can you post your database schema.
Re: MYSQL
iam emailing to you
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: MYSQL
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.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: MYSQL
Is this what you want?SELECT leads, COUNT(*) affiliate_id WHERE '$afid' GROUP BY '$afid'
Code: Select all
SELECT COUNT(lead_id) as total, affiliate_id GROUP BY affiliate_idRe: MYSQL
yes i want to count how many of the same values are in column affiliate_id
how would I echo that out?
$result = ??
how would I echo that out?
$result = ??
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: MYSQL
You need to learn the basics!
This might help...
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
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
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: MYSQL
Oh I see.
This this should be it...
This this should be it...
Code: Select all
SELECT COUNT(lead_id) as total WHERE affiliate_id = '$afid'
Re: MYSQL
no, does not work 
- novice4eva
- Forum Contributor
- Posts: 327
- Joined: Thu Mar 29, 2007 3:48 am
- Location: Nepal
Re: MYSQL
With what you are posting, all you will get from us is what jaoudestudios has already given it to you.....

radium35 wrote:![]()
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
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 thisjaoudestudios wrote:Oh I see.
This this should be it...Code: Select all
SELECT COUNT(lead_id) as total WHERE affiliate_id = '$afid'
Code: Select all
SELECT COUNT(lead_id) as total FROM leads WHERE affiliate_id = '$afid'
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: MYSQL
Oh yes sorry I forgot the FROM - was running out the house when I wrote it - thanks novice4eva 
