Re: multiplying

From: Date: Fri, 11 Apr 2003 15:51:48 +0000
Subject: Re: multiplying
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-143529@lists.php.net to get a copy of this message
reset your variables, e.g. $totalm=0; wherever needed joe wrote:
I have this code to print many hours but it seems to be adding the hours in total user by user this is wierd $link = mysql_connect("localhost", "", "")
       or die("Could not connect");
      mysql_select_db("cdmvirt_ft") or die("Could not select database");
    $query = "SELECT * FROM pirep WHERE pilot_id='mvc007'";
$result = mysql_query($query) or die("Query failed"); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
      $hhmm=explode(':',$line['flight_hhmm']);
       $totalm+=$hhmm[0]*60+$hhmm[1];
        $mvc007=floor($totalm / 60).':'.($totalm % 60);
} mysql_free_result($result); $link = mysql_connect("localhost", "", "")
       or die("Could not connect");
      mysql_select_db("cdmvirt_ft") or die("Could not select database");
       $query = "SELECT flight_hhmm FROM pirep WHERE pilot_id='mvc069'";
$result = mysql_query($query) or die("Query failed"); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $hhmm=explode(':',$line['flight_hhmm']);
       $totalm+=$hhmm[0]*60+$hhmm[1];
} $mvc069=floor($totalm / 60).':'.($totalm % 60); mysql_free_result($result);
       $link = mysql_connect("localhost", "", "")
       or die("Could not connect");
      mysql_select_db("cdmvirt_ft") or die("Could not select database");
$query = "SELECT flight_hhmm FROM pirep WHERE pilot_id='mvc101'"; $result = mysql_query($query) or die("Query failed"); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
       $hhmm=explode(':',$line['flight_hhmm']);
       $totalm+=$hhmm[0]*60+$hhmm[1];
} $mvc101=floor($totalm / 60).':'.($totalm % 60); mysql_free_result($result); if the first user has 10 hours the second has 20 this is what I get user1 = 10 user 2 = 30 and so on what am I doing wrong


« previous php.general (#143529) next »