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
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! :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.