PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 31st, 2002, 04:39 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
help with reports

I need to run a report that will list every month in a spacific year and also list every rep and the number of contacts the have for each month any suggestions

Reply With Quote
  #2  
Old October 31st, 2002, 05:13 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: help with reports

is this info stored in a database? if so, let's see the table layout...then i can show you a query to get that info.....


Reply With Quote
  #3  
Old October 31st, 2002, 07:04 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
RE: help with reports

yes it is in a Msql database. I have 2 tables.

Table1 Reps
id,r_code,fname,lname

Table2 delegates
id,t_stamp,fname,spouse,lname,address,city,state,z ip,phonenumber,rep,ccat,status,email,notes

I need to use r_code for the reps and t_stamp for the months.

Reply With Quote
  #4  
Old October 31st, 2002, 07:13 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: help with reports

does delgate.rep = reps.r_code ??


Reply With Quote
  #5  
Old October 31st, 2002, 07:26 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
RE: help with reports

yes it does

Reply With Quote
  #6  
Old October 31st, 2002, 07:43 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: help with reports

This will pull all the info sorted by t_stamp and then the r_code...

select reps.*, delegates.* from reps,delegates where delegates.rep=reps.r_code order by t_stamp, r_code

Reply With Quote
  #7  
Old October 31st, 2002, 09:55 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
RE: help with reports

that works good but i need some thing like this
|jan|feb|march|april|may|june|july|aug|sept|oct|no v|
----------------------------------------------------
Rep1 |15|
Rep2 |20|
Rep3 |10|

Reply With Quote
  #8  
Old October 31st, 2002, 10:21 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: help with reports

Assuming that the t_stamp field is a mysql timestamp..i would do something like this in php:

php Code:
Original - php Code
  1.  
  2. $query = "select reps.r_code, UNIX_TIMESTAMP(delegates.t_stamp) as getmonth, delegates.id from reps,delegates where delegates.rep=reps.r_code order by t_stamp, r_code";
  3. $result = mysql_query($query);
  4. while($row = mysql_fetch_assoc($result)) {
  5.   $month = strftime("%m", $row['getmonth']);
  6.   $rep = $row['r_code'];
  7.   if(isset($report[$month]["$rep"])) {
  8.     $report[$month]["$rep"]++;
  9.   } else {
  10.     $report[$month]["$rep"] = 1;
  11.   }
  12. }


Now, I haven't tested that, but it should give you an idea...after that runs, you will have all the data you need in a multi-dimensional array. Then, all you have to do is display it....

Reply With Quote
  #9  
Old October 31st, 2002, 10:45 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
RE: help with reports

Either i didn't get it or i'm not understanting how to display it all i get is

TP 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
AH 10
BH 10
BH 10
BH 10
BH 10
BH 10
BL 10
BL 10
BL 10
BL 10
BL 10
BL 10
CC 10
CC 10
CC 10
CC 10
CS 10
CS 10
CS 10
CS 10
CS 10
NH 10
NH 10
NH 10
NH 10


Reply With Quote
  #10  
Old October 31st, 2002, 10:51 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
RE: help with reports

ok i think i was telling you wrong what i need this to do is
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.

Reply With Quote
  #11  
Old October 31st, 2002, 11:02 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: help with reports

Like I said, you still need to work out the display system...here is some pseudo code...
Code:
start table
new row
display one empty <td></td>

for i = 1 to 12
{ <td>convert i to monthname</td> }

end row

foreach rep {
new row
echo <td>$rep</td>
  for i = 1 to 12
   { if isset($report[$i]["$rep"]) echo <td>$report[$i]["$rep"]</td>
     else echo <td>0</td>
   }
end row
}
end table

Reply With Quote
  #12  
Old November 1st, 2002, 01:23 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
RE: help with reports

Sorry I'm Still not able to get this to work. Is there anything i can do to help.

Reply With Quote
  #13  
Old November 1st, 2002, 01:28 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: help with reports

Where are you having a problem? Can we see some code that you are not able to get to work?

Reply With Quote
  #14  
Old November 1st, 2002, 01:53 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
RE: help with reports

<?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>";
// new row
echo "<td></td>";
for i = 1 to 12
{ <td>convert i to monthname</td> }
// end row
foreach rep {
echo "<td>$rep</td>";
for i = 1 to 12
{ if isset($report[$i]["$rep"]) echo <td>$report[$i]["$rep"]</td>
else echo <td>0</td>
}
// end row
echo "</tr>";
}
// end table
echo "</table>";
?>

Reply With Quote
  #15  
Old November 1st, 2002, 01:56 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: help with reports

the proper syntax for for loops is:

for($var = 0; $var < somenumber; $var++)

foreach loops:

foreach($something as $asmallerpart)


Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > help with reports


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread