Avatar billede kazmirex Nybegynder
12. august 2005 - 01:29 Der er 8 kommentarer og
1 løsning

Give samme resultat i while lykke

Denne while give samme resultat som førrste gang den køre, i alle tilfæjde men hvorfor hvor min fejl?

$i=0;
$check = time();
while ($i < $num) {

    $SvrTime    =    mysql_result($result,$i,"vc_time");
   

$diff = $time - $vc_Time;
$daysDiff = 0;
$hrsDiff = 0;
$minsDiff = 0;
$secsDiff = 0;
$elap_time = 0;

$sec_in_a_day = 60*60*24;

while($diff >= $sec_in_a_day){
$daysDiff++; $diff -= $sec_in_a_day;
}
$sec_in_an_hour = 60*60;

while($diff >= $sec_in_an_hour){
$hrsDiff++;
$diff -= $sec_in_an_hour;
}

$sec_in_a_min = 60;

while($diff >= $sec_in_a_min){
$minsDiff++;
$diff -= $sec_in_a_min;
}

$secsDiff = $diff;


$elap_time = ($minsDiff.' minute'.(($minsDiff <> 1) ? "s" : "").', '.$secsDiff.' second'.(($secsDiff <> 1) ? "s" : ""));


echo("<p><b>Diff " . $elap_time . ".</b></p>");


$i++;
}

Output:
2005-08-12 00:00:36
Diff 43 minutes, 42 seconds.

2005-08-10 17:24:25
Diff 43 minutes, 42 seconds.

2005-08-10 17:37:31
Diff 43 minutes, 42 seconds.

2005-08-10 17:41:08
Diff 43 minutes, 42 seconds.

2005-08-10 17:48:34
Diff 43 minutes, 42 seconds.
Avatar billede kazmirex Nybegynder
12. august 2005 - 01:30 #1
Det er $SvrTime    =    mysql_result($result,$i,"vc_time");

men fejlen der stadig med
Det er $vc_Time =    mysql_result($result,$i,"vc_time");
Avatar billede nielle Nybegynder
12. august 2005 - 08:44 #2
Jeg gætter på at denne:

$diff = $time - $vc_Time;

- skal rettes til:

$diff = $check - $vc_Time;
Avatar billede kazmirex Nybegynder
12. august 2005 - 10:51 #3
Hvad er fejlen her?

$i=0;
$check = time();
while ($i < $num) {

    $SvrID        =    mysql_result($result,$i,"auto_id");
    $SvrName    =    mysql_result($result,$i,"vc_svrname");
    $SvrTime    =    mysql_result($result,$i,"vc_checktime");
   
    echo $SvrID;
    echo "<br>";
    echo $SvrName;
    echo "<br>";
    echo $SvrTime;

//****
$diff = $check - $SvrTime ;
$daysDiff = 0;
$hrsDiff = 0;
$minsDiff = 0;
$secsDiff = 0;
$elap_time = 0;

$sec_in_a_day = 60*60*24;

while($diff >= $sec_in_a_day){
$daysDiff++; $diff -= $sec_in_a_day;
}
$sec_in_an_hour = 60*60;

while($diff >= $sec_in_an_hour){
$hrsDiff++;
$diff -= $sec_in_an_hour;
}

$sec_in_a_min = 60;

while($diff >= $sec_in_a_min){
$minsDiff++;
$diff -= $sec_in_a_min;
}

$secsDiff = $diff;


$elap_time = ($minsDiff.' minute'.(($minsDiff <> 1) ? "s" : "").', '.$secsDiff.' second'.(($secsDiff <> 1) ? "s" : ""));

//***

echo("<p><b>This page took " . $elap_time . " to fully execute.</b></p>");

$diff = 0;
$daysDiff = 0;
$hrsDiff = 0;
$minsDiff = 0;
$secsDiff = 0;
$elap_time = 0;

$i++;
}

Update 1
ARHK
2005-08-12 00:00:36

This page took 19 minutes, 22 seconds to fully execute.
2
109
2005-08-10 17:24:25

This page took 19 minutes, 22 seconds to fully execute.
3
101
2005-08-10 17:37:31

This page took 19 minutes, 22 seconds to fully execute.
4
118
2005-08-10 17:41:08

This page took 19 minutes, 22 seconds to fully execute.
5
NOTES
2005-08-10 17:48:34

This page took 19 minutes, 22 seconds to fully execute.
Avatar billede nielle Nybegynder
12. august 2005 - 11:17 #4
Kan du ikke lige fortælle hvor i at du mener at det er noget forkert der kommer ud på skærmen?
Avatar billede kazmirex Nybegynder
12. august 2005 - 12:12 #5
2005-08-12 00:00:36 - time() == Diff: This page took 19 minutes, 22 seconds to fully execute.

2005-08-10 17:24:25 - time() == Diff: This page took 19 minutes, 22 seconds to fully execute.


Variablen
$SvrTime har ingen effect den, bruge KUN $SvrTime i første gennem løb

$diff = $check - $SvrTime ;

Der for give alt samme svar uaset hvad $SvrTime er

Hvordan kan det være

$SvrTime er forskelig hvert gennem løb men den variabel her blive kunne tilpasse første gannem løb
Avatar billede nielle Nybegynder
12. august 2005 - 12:46 #6
Prøv også at udskrive $diff for hvert af dine løkkegennemløb.

Hvordan er vc_checktime defineret i databasen? Er det et datetime felt eller en streg eller noget andet?
Avatar billede kazmirex Nybegynder
12. august 2005 - 14:02 #7
$num=mysql_numrows($result);
   

$i=0;
$check = time();
while ($i < $num) {

    $SvrID        =    mysql_result($result,$i,"auto_id");
    $SvrName    =    mysql_result($result,$i,"vc_svrname");
    $SvrTime    =    mysql_result($result,$i,"vc_checktime");
   
//    echo mysql_result($result,$i,"vc_checktime");
    echo "SvrTime Før diff = check: (vc_checktime == type Timestamp) ";
    echo $SvrTime;
    echo $SvrID;
    echo "<br>";
    echo $SvrName;
    echo "<br>";
    echo $SvrTime;

//****
$diff = $check - mysql_result($result,$i,"vc_checktime");
echo "<br>";
echo "Diff: ";
echo $diff;
echo "<br>";
echo "Check: ";
echo $check;
echo "<br>";
echo "SvrTime Efter diff = check: ";
echo $SvrTime;

$daysDiff = 0;
$hrsDiff = 0;
$minsDiff = 0;
$secsDiff = 0;
$elap_time = 0;

$sec_in_a_day = 60*60*24;

while($diff >= $sec_in_a_day){
$daysDiff++; $diff -= $sec_in_a_day;
}
$sec_in_an_hour = 60*60;

while($diff >= $sec_in_an_hour){
$hrsDiff++;
$diff -= $sec_in_an_hour;
}

$sec_in_a_min = 60;

while($diff >= $sec_in_a_min){
$minsDiff++;
$diff -= $sec_in_a_min;
}

$secsDiff = $diff;


$elap_time = ($minsDiff.' minute'.(($minsDiff <> 1) ? "s" : "").', '.$secsDiff.' second'.(($secsDiff <> 1) ? "s" : ""));

//***

echo("<p><b>This page took " . $elap_time . " to fully execute.</b></p>");

$diff = 0;
$daysDiff = 0;
$hrsDiff = 0;
$minsDiff = 0;
$secsDiff = 0;
$elap_time = 0;

$i++;
}

output:

SvrTime Før diff = check: 2005-08-12 00:00:361
ARHK
2005-08-12 00:00:36
Diff: 1123846208
Check: 1123848213
SvrTime Efter diff = check: 2005-08-12 00:00:36

This page took 30 minutes, 8 seconds to fully execute.
SvrTime Før diff = check: 2005-08-10 17:24:252
109
2005-08-10 17:24:25
Diff: 1123846208
Check: 1123848213
SvrTime Efter diff = check: 2005-08-10 17:24:25

This page took 30 minutes, 8 seconds to fully execute.
SvrTime Før diff = check: 2005-08-10 17:37:313
101
2005-08-10 17:37:31
Diff: 1123846208
Check: 1123848213
SvrTime Efter diff = check: 2005-08-10 17:37:31

This page took 30 minutes, 8 seconds to fully execute.
SvrTime Før diff = check: 2005-08-10 17:41:084
118
2005-08-10 17:41:08
Diff: 1123846208
Check: 1123848213
SvrTime Efter diff = check: 2005-08-10 17:41:08

This page took 30 minutes, 8 seconds to fully execute.
SvrTime Før diff = check: 2005-08-10 17:48:345
NOTES
2005-08-10 17:48:34
Diff: 1123846208
Check: 1123848213
SvrTime Efter diff = check: 2005-08-10 17:48:34

This page took 30 minutes, 8 seconds to fully execute.
Avatar billede kazmirex Nybegynder
12. august 2005 - 15:44 #8
lukket
Avatar billede myplacedk Nybegynder
12. august 2005 - 22:59 #9
Du skal lige accptere et svar før spørgsmålet bliver lukket.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester