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
https://forums.phpfreaks.com/topic/137404-solved-help-looping-a-select-count/
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>";
}

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>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.