Jump to content

What is wrong with this?


electrix

Recommended Posts

I've been writing this for a couple of hours now.

I thought i've found most mistakes and errors but the result is not correct!

Sometimes the var $KS is null? Why? Where is the error?

 

$K=$_POST[kday];
$M=$_POST[mday];
$P=0;
$S=0;
$F=1;

$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd") or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection) or die("Couldn't select database.");

$result123 = mysql_query("SELECT hours,date2, projekt FROM tidrapport_projekt_timmar WHERE username='$row1[0]' AND date2 BETWEEN '$begin' AND '$end' ORDER BY date2"); 
while ($row123=mysql_fetch_array($result123)) { 


if("$F"=="0" AND "$row123[projekt]"!="Sjuk") { 
if($P>$M) { if($S>$K) { $KS=$KS+$K; } else { $KS=$KS+$S; } $P=0; $S=0; }


} ELSE {

if($row123[projekt]=="Sjuk") { $S++; $F="0"; }
if($row123[projekt]!="Sjuk") { $P++; $F=1; }
     }

}

echo "<td align='center'>";
echo $KS;
echo "</td>";

Link to comment
https://forums.phpfreaks.com/topic/44752-what-is-wrong-with-this/
Share on other sites

$KS is being defined inside an if- it will be defined only if $F is 0 and $row123['projekt'] is not "Sjuk". You don't give it any value inside the else, so it will be NULL.

 

Orio.

 

Ah! I found the problem.

 

Add $KS = 0; at the top and a "$F=1;" after "$P=0; $S=0;".

That was why the loop wouldn't loop  ;)

 

Thnx everyone! :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.