MYSQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

MYSQL

Post 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?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: MYSQL

Post 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.
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: MYSQL

Post 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.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: MYSQL

Post by jaoudestudios »

Can you post your database schema.
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: MYSQL

Post by radium35 »

iam emailing to you
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: MYSQL

Post 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.
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: MYSQL

Post by radium35 »

Image
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: MYSQL

Post 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?
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: MYSQL

Post 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 = ??
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: MYSQL

Post 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
}
 
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: MYSQL

Post 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
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: MYSQL

Post by jaoudestudios »

Oh I see.

This this should be it...

Code: Select all

 
SELECT COUNT(lead_id) as total WHERE affiliate_id = '$afid'
 
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: MYSQL

Post by radium35 »

no, does not work :drunk:
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: MYSQL

Post 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:
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: MYSQL

Post by jaoudestudios »

Oh yes sorry I forgot the FROM - was running out the house when I wrote it - thanks novice4eva :)
Post Reply