RE: looping code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>From what I can see is that you're not actually looping anything?

   while( !$done  ) {
       $row = mysql_fetch_row( $result );
       if( !$row ) { 
           $done = 1;
       }

This doesn't loop through your query, least not in my eyes it doesn't.
Why not:

while ($rows = mysql_fetch_array($result)) {

	if ($done != 0){
		
		if( $rows['t_id'] != $rows['prev_t_id'] ) {
		   if( $rows['prev_e_status'] == "OPEN" ) {
			$openTickets++;
			   if( $rows['prev_e_assignedto'] == $user &&
isset($user) )
				$userTickets++;
				$done = 1;
			   }
		   }
	}

This might work... though I have no clue what $done is for. It looks
like that you are setting $done after each loop but the problem is that
$done will equal 1 after the first loop and stop looping.

Aaron


-----Original Message-----
From: Khristopher_Klaich@nywd.uscourts.gov
[mailto:Khristopher_Klaich@nywd.uscourts.gov] 
Sent: August 6, 2003 2:44 PM
To: PHP DB
Subject:  looping code

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:


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 );

   $row = mysql_fetch_row( $result );

   $prev_e_id = $row[0]; 
   $prev_t_id = $row[1]; 
   $prev_e_status = $row[2]; 
   $prev_e_assignedto = $row[3];

   $done = 0;
   while( !$done  ) {
       $row = mysql_fetch_row( $result );
       if( !$row ) { 
           $done = 1;
       }
 
       $e_id = $row[0]; 
       $t_id = $row[1]; 
       $e_status = $row[2]; 
       $e_assignedto = $row[3];

       if( $t_id != $prev_t_id ) {
           if( $prev_e_status == "OPEN" ) {
               $openTickets++;
               if( $prev_e_assignedto == $user && isset($user) )
                   $userTickets++;
           }
       }
 
       $prev_e_id = $e_id;
       $prev_t_id = $t_id;
       $prev_e_status = $e_status;
       $prev_e_assignedto = $e_assignedto;
   }
 
   print "Open Tickets: $openTickets<br>\n";
   print "Assigned to you: $userTickets<br>\n";
}



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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux