Forum Moderators: coopster
function leadstablereport_display_addon() {
$security_admin = login::loginCheck('Admin', true);
$security_agent = login::loginCheck('Agent', true);
if ($security_admin === true ¦¦ $security_agent === true) {
global $config, $conn;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$sql = "SELECT nhm_associate, COUNT(nhm_associate) FROM registration_table GROUP BY nhm_associate";
while($row = mysql_fetch_array($sql)){
$display .='There are '. $row['COUNT(nhm_associate)'] .' '. $row['nhm_associate'] . ' items.<br />';
}
} else {
// DISPLAY A WARNING TO THE PAGE AS ADMIN/AGENT IS NOT LOGGED
$display .= 'YOU ARE NOT AUTHORIZED TO VIEW THIS PAGE.';
}
return $display;
}
Here is my current function below; which returns this below...how is i the letter "S" getting in there?:
_________________________________________________________
There are S S items.
There are S S items.
There are S S items.
There are S S items.
There are S S items.
_________________________________________________________
function leadstablereport_display_addon() {
$security_admin = login::loginCheck('Admin', true);
$security_agent = login::loginCheck('Agent', true);
if ($security_admin === true ¦¦ $security_agent === true) {
global $config, $conn;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$display .='';
$sql = 'SELECT nhm_associate, COUNT(nhm_associate) FROM registration_table GROUP BY nhm_associate';
// EXECUTE
$recordSet = $conn->Execute($sql);
// CHECK IF ERROR
if ($recordSet === false) {
$misc->log_error($sql);
}
// KEEP READING TILL THE END
while (!$recordSet->EOF) {
$display .='There are '. $sql["COUNT(nhm_associate)"] .' '. $sql["nhm_associate"] . ' items.<br />';
// GO GET THE NEXT ONE
$recordSet->MoveNext();
}
} else {
// DISPLAY A WARNING TO THE PAGE AS ADMIN/AGENT IS NOT LOGGED
$display .= 'YOU ARE NOT AUTHORIZED TO VIEW THIS PAGE. PLEASE GO TO THE BOTTOM OF THE PAGE AND LOG IN!';
$recordSet->MoveNext();
}
return $display;
}
$display .='There are '. $sql["COUNT(nhm_associate)"] .' '. $sql["nhm_associate"] . ' items.<br />';
you can assign a varname like so
$sql = 'SELECT nhm_associate, COUNT(nhm_associate) as thebigcount FROM registration_table GROUP BY nhm_associate';
and then
$display .='There are '. $sql['thebigcount'] .' '. $sql["nhm_associate"] . ' items.<br />';
There are 9 Candace Shan items.
There are 155 Debbie Orme items.
There are 75 Jesse Stoneberg items.
There are 58 Joe Grubiak items.
There are 9 Not Specified items.
______________________________________________________
What i want to do now, and maybe you can help me with is build upon this...
i want to put each agent in a separate row...in a table.
______________________________________________________
function leadstablereport_display_addon() {
$security_admin = login::loginCheck('Admin', true);
$security_agent = login::loginCheck('Agent', true);
if ($security_admin === true ¦¦ $security_agent === true) {
global $config, $conn;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$sql = 'SELECT nhm_associate, COUNT(nhm_associate) AS totalcount FROM registration_table GROUP BY nhm_associate';
// EXECUTE
$recordSet = $conn->Execute($sql);
// CHECK IF ERROR
if ($recordSet === false) {
$misc->log_error($sql);
}
// KEEP READING TILL THE END
while (!$recordSet->EOF) {
$tc = $misc->make_db_unsafe ($recordSet->fields['totalcount']);
$nhma = $misc->make_db_unsafe ($recordSet->fields['nhm_associate']);
$display .='There are '. $tc .' '. $nhma . ' items.<br />';
// GO GET THE NEXT ONE
$recordSet->MoveNext();
}
} else {
// DISPLAY A WARNING TO THE PAGE AS ADMIN/AGENT IS NOT LOGGED
$display .= 'YOU ARE NOT AUTHORIZED TO VIEW THIS PAGE. PLEASE GO TO THE BOTTOM OF THE PAGE AND LOG IN!';
$recordSet->MoveNext();
}
return $display;
}
echo '<table>'; // start your table before
while (!$recordSet->EOF) {
$tc = $misc->make_db_unsafe ($recordSet->fields['totalcount']);
$nhma = $misc->make_db_unsafe ($recordSet->fields['nhm_associate']);
$display .='There are '. $tc .' '. $nhma . ' items.<br />';
// GO GET THE NEXT ONE
$recordSet->MoveNext();
}
echo '</table>'; // close your table after
and then you just play with your html in your output line
from
$display .='There are '. $tc .' '. $nhma . ' items.<br />';
to
$display .='<tr><td>There are '. $tc .' '. $nhma . ' items.</td></tr>';
obviously this is a very simple table but imagine you get my drift
Here is my next step.... the function below, now goes back 7 days, and checks to see how many records any agent has entered during that timeframe....
using the DATE_SUB function... i learned that at least!
Now, what i want to do is show a weekly calendar of the last seven days, and what day each entry was entered....
(yeah, basically....im sure that sounds dumb)
so it would look something similar to this:
---------------------------------------------------
Agent___7/7___7/8___7/9___7/10___7/11___7/12___7/13
---------------------------------------------------
Agent1___1_____1_____2______2______0_____9______1
Agent2___0_____0_____0______1______1_____1______1
---------------------------------------------------
How do you show the dates and 7 days prior, also calling how many entries were entered that day?
From my own thinking, i thought i would have to define a variable with a query for each interval day?
i.e. INTERVAL 7 DAY, INTERVAL 6 DAY, INTERVAL 5 DAY
and then place each of those in its own <td>?
___________________________________________________________
function leadstablereport_display_addon() {
$security_admin = login::loginCheck('Admin', true);
$security_agent = login::loginCheck('Agent', true);
if ($security_admin === true ¦¦ $security_agent === true) {
global $config, $conn;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$sql = 'SELECT nhm_associate, COUNT(nhm_associate) AS totalcount FROM registration_table WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= entry_time GROUP BY nhm_associate ';
// EXECUTE
$recordSet = $conn->Execute($sql);
// CHECK IF ERROR
if ($recordSet === false) {
$misc->log_error($sql);
}
// KEEP READING TILL THE END
$display .='<table width="100%" border="1" style=border-collapse:collapse; border-style:solid;>'; // start your table before
$display .='<tr><td><h1 align="center">Registration Leads Entered Last Week</h1></td></tr>';
while (!$recordSet->EOF) {
$tc = $misc->make_db_unsafe ($recordSet->fields['totalcount']);
$nhma = $misc->make_db_unsafe ($recordSet->fields['nhm_associate']);
$display .='<tr><td>' . $nhma . ' has entered ' . $tc . ' last week.</td></tr>';
// GO GET THE NEXT ONE
$recordSet->MoveNext();
}
$display .='</table>'; // close your table after
} else {
// DISPLAY A WARNING TO THE PAGE AS ADMIN/AGENT IS NOT LOGGED
$display .= 'YOU ARE NOT AUTHORIZED TO VIEW THIS PAGE. PLEASE GO TO THE BOTTOM OF THE PAGE AND LOG IN!';
$recordSet->MoveNext();
}
return $display;
}
if you put them all in one table it may take a chunk of work
does the table have a column for date or store a timestamp, I assume it does
group by associate and sort by date, then loop through them to properly display the results
you might want to have this generated and store it as an html page/table if you are going to access this often
you have the total per associate for last week, leave that, make it clickable and that could bring up your 7 day per associate
so the original query, that only counts how many records that were entered the prior 7 days, make that a link to bring up the weekly per day count?
if you put them all in one table it may take a chunk of work
so make each agent as their own table right?
does the table have a column for date or store a timestamp, I assume it does
yes, the column name in the table is "entry_time" and is set to "datetime" datatype...i was told that is easier for calculations?
group by associate and sort by date, then loop through them to properly display the results
didnt follow you on this one...
you might want to have this generated and store it as an html page/table if you are going to access this often
yes, this is being displayed in a secure area for authorized users, on my web server.