electrix Posted March 29, 2007 Share Posted March 29, 2007 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>"; Quote Link to comment Share on other sites More sharing options...
Orio Posted March 29, 2007 Share Posted March 29, 2007 $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. Quote Link to comment Share on other sites More sharing options...
rcorlew Posted March 29, 2007 Share Posted March 29, 2007 Beat me to it, and I always prefer to use 1 and 2 not 0 and 1, 0's can set as null when using sql and php together, better to use another number is my pesonal prefrence. Quote Link to comment Share on other sites More sharing options...
electrix Posted March 29, 2007 Author Share Posted March 29, 2007 $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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.