Page 1 of 1

help with reports

Posted: Fri Nov 01, 2002 10:47 am
by tmurphy
I need report that
list each month in the year across the top
then list distinct each rep across the left hand side
then tell how many contacts they recieved for each month.

this is what i have so far

<?php
require_once ("./application/backend.php");

// connect to db

$connection = @mysql_connect("$authlib->server", "$authlib->db_user", "$authlib->db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($authlib->database, $connection) or die("Couldn't select database.");

$query = "select reps.r_code, UNIX_TIMESTAMP(contacts.t_stamp) as getmonth, contacts.id from
reps,contacts where contacts.rep=reps.r_code order by t_stamp, r_code";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
$month = strftime("%m", $row['getmonth']);
$rep = $row['r_code'];
if(isset($report[$month]["$rep"])) {
$report[$month]["$rep"]++;
} else {
$report[$month]["$rep"] = 1;
}

}

// start table
echo "<TABLE ALIGN=\"CENTER\" CELLPADDING=\"3\" WIDTH=\"100 %\" BORDER=\"0\">";
echo "<TR>";

echo "<td></td>";

for ($i = 1; $i <= 12; $i++){
echo "<td>" . date("M", strtotime("2002-$i-22")) . "</td>\n";
}

foreach ($rep as $val) {
echo "<td>$rep</td>";
for ($i = 1; $i < 12;$i++){
if (isset($report[$i]["$rep"])){
echo "<td>$report[$i]['$rep']</td>";
}
else{
echo "<td>0</td>";
}

echo "</tr>";
}
}
echo "</table>";
?>

when i run this i get a
Warning: Invalid argument supplied for foreach() in /home/mdptoday/www/test2.php on line 33

Can anyone help out?? :?

Re: help with reports

Posted: Fri Nov 01, 2002 11:01 am
by seg
tmurphy wrote:foreach ($rep as $val)
Warning: Invalid argument supplied for foreach() in /home/mdptoday/www/test2.php on line 33

Code: Select all

foreach($rep as $val);
take the space out
http://www.php.net/manual/en/control-st ... oreach.php

Posted: Fri Nov 01, 2002 11:11 am
by tmurphy
I tried that and i get the same error but it does list 0's down the left hand side

Posted: Fri Nov 01, 2002 11:16 am
by tmurphy
you can view the page at

http://www.mdptoday.com/test2.php

Posted: Fri Nov 01, 2002 11:18 am
by seg
tmurphy wrote:I tried that and i get the same error but it does list 0's down the left hand side
I don't see how you could get the _same_ error but it echos the 0's. Regarless, though, I don't see anything else wrong without pulling apart your code and giving it structure(which I'm not going to do.) Read your error message, including the line number, and keep working on it.