Jump to content

[SOLVED] Help looping a SELECT count(*)


rkteach

Recommended Posts

Hi all, need help looping a Select count(*) from mysql database.

data is pulling from a form where they choose where they heard about us... for marketing.

I can show an individual result using

 

/////////////code///////////////

<?php

$res = mysql_query("SELECT count(*) FROM Training_Inquiries WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Contact_Date AND Ad_tracker='Google'");

$res = mysql_fetch_array($res);

echo $res[0]."  Selected Google.<br>";

?>

/////////////end code///////////////

But what id like to do is some how loop and/or group the results of "Ad_tracker"

because the choice is dynamic and my be change or added in an admin (drop down menu)

 

you can see im posting last 30 days if the table "Ad_tracker" = 'Google'

and can do this for each choice... but if we add another choice in the admin to the form i would have to code a new entry...

 

If anyone has any idea that would be great...

Link to comment
Share on other sites

ok off the top of my head here but it might work  ;):

 

"SELECT count(*) as num, Ad_Tracker FROM Training_Inquiries WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Contact_Date GROUP BY Ad_tracker"

while ($r = mysql_fetch_array($res)) 
{
   echo $r['num']."  Selected ".$r['Ad_Tracker'].".<br>";
}

Link to comment
Share on other sites

<?php

$res = mysql_query("SELECT COUNT(Ad_tracker) FROM Training_Inquiries WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Contact_Date AND Ad_tracker='Google' GROUP BY Ad_tracker");

$res = mysql_fetch_array($res);     

echo $res[0]."  Selected Google.<br>";

?>

Link to comment
Share on other sites

thanks Violet Crayon & PHPain

thats exacty what i needed


<?php
$res = mysql_query("SELECT count(*) as num, Ad_Tracker FROM Training_Inquiries WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Contact_Date GROUP BY Ad_tracker");
while ($r = mysql_fetch_array($res)) 
{
   echo $r['num']."  Selected ".$r['Ad_Tracker'].".<br>";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.