help with reports

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
tmurphy
Forum Newbie
Posts: 3
Joined: Fri Nov 01, 2002 10:47 am
Location: Apopka

help with reports

Post 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?? :?
seg
Forum Commoner
Posts: 38
Joined: Thu Oct 31, 2002 12:08 pm
Location: Northern, VA
Contact:

Re: help with reports

Post 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
tmurphy
Forum Newbie
Posts: 3
Joined: Fri Nov 01, 2002 10:47 am
Location: Apopka

Post by tmurphy »

I tried that and i get the same error but it does list 0's down the left hand side
tmurphy
Forum Newbie
Posts: 3
Joined: Fri Nov 01, 2002 10:47 am
Location: Apopka

Post by tmurphy »

you can view the page at

http://www.mdptoday.com/test2.php
seg
Forum Commoner
Posts: 38
Joined: Thu Oct 31, 2002 12:08 pm
Location: Northern, VA
Contact:

Post 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.
Post Reply