Hello all I have a helpdesk application that was written in php and I would like to create a script that will e-mail the systems staff how many open helpdesk tickets they have. There are 10 users and I can wrtie a script no problem to do a count and then e-mail that to a user I just have no idea how the heck to loop it through all of the users .....

Here is my code for one user if they are logged in if anyone can help me or lead me in the right direction I would appreicate it very much my brain is just not working today:

why don't you use mysql to do the heavy lifting? you could use COUNT and GROUP BY to figure out the whole thing in one go pretty much.

function showSummary() {
global $user, $mysql_link;
$openTickets = 0;
$userTickets = 0;
$query = "SELECT events.e_id, events.t_id, events.e_status, " .
"events.e_assignedto, ticket.t_id FROM events,ticket " .
" WHERE events.t_id = ticket.t_id ORDER BY " .
" events.t_id, events.e_id;";
$result = query( $query );

i think your query should be more like

select e.e_status, e.e_assignedto, count(1) from events e group by e.e_assignedto, e.e_status

then you want to do

$result=mysql_query($query) or die(mysql_error());

ALWAYS check the return value of mysql_query. it will save you from much headscratching later on if you make a silly typo or something.

the rest of the script would be something like:


while ($r=mysql_fetch_assoc($result)) {
    $user[$r['e_assignedto']][$r['e_status']] += 1;

foreach ($user as $u) {
    $count = 0;
    print "Ticket summary for $u:\n";
    foreach ($user[$u] as $x) {
        print "Ticket type $x: " . $user[$u][$x] . "\n";
        $count += $user[$u][$x];
    print "Total tickets: $count\n";

basically you create an array of users, each entry in the array is another array containing the ticket status and a count.

if you want to see it visually, do print_r($user) right before the first foreach.


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to