Re: comparison problem

From: Date: Wed, 10 Oct 2001 19:05:43 +0000
Subject: Re: comparison problem
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-13206@lists.php.net to get a copy of this message
On Wed, 10 Oct 2001 15:18:57 +0200 "Bart Verbeek" <b.verbeek@creative-edge.nl> wrote: > <?PHPCODE > #AANTAL UREN SPLITTEN (INT/DEC) EN KLOKJES WEERGEVEN > $uren_tegoed = $row_uren["uren"] - $row_uren["uren_verbruikt"]; > > list ($klok_int, $klok_dec) = split('.', $uren_tegoed); > if ($klok_dec >= "01" AND $klok_dec <= "25") { > $klok_dec = "25"; > $klok_dec_image = "klok_4-1.gif"; > } elseif ($klok_dec >= "26" AND $klok_dec <= "50") { > $klok_dec ="50"; > $klok_dec_image = "klok_4-2.gif"; > } elseif ($klok_dec >= "51" AND $klok_dec <= "75") { > $klok_dec ="75"; > $klok_dec_image = "klok_4-3.gif"; > } elseif ($klok_dec >= "76" AND $klok_dec <= "99" || $klok_dec == "0" || > !isset($klok_dec)) { > $klok_dec ="0"; > $klok_dec_image = "klok_4-0.gif"; > --$klok_int; > } else { > $klok_dec ="ERROR"; > $klok_dec_image = "ERROR"; > } > PHPCODE?> Hi Bart, Without trying out your code, I suspect that the problem was the grouping of the last "elseif". Compound logical comparisons have to be grouped using "(" and ")" or they must be seperated out, and mixing "and" and "or" certainly qualify. To make your code easier for me to understand I did some reformatting and seperated the compound logical comparison. Otherwise, I can't see anything wrong with your code. "Explode()" seems to work better than "split()" in this case. This is what I came up with. <?PHP #AANTAL UREN SPLITTEN (INT/DEC) EN KLOKJES WEERGEVEN $uren_tegoed = $row_uren["uren"] - $row_uren["uren_verbruikt"]; $array = explode('.', $uren_tegoed); # To save typing, I'll do this ... $klok_int = $array[0]; $klok_dec = $array[1]; if ($klok_dec == "0" OR !isset($klok_dec) { $klok_dec ="0"; $klok_dec_image = "klok_4-0.gif"; --$klok_int; } elseif ($klok_dec >= "01" AND $klok_dec <= "25") { $klok_dec = "25"; $klok_dec_image = "klok_4-1.gif"; } elseif ($klok_dec >= "26" AND $klok_dec <= "50") { $klok_dec ="50"; $klok_dec_image = "klok_4-2.gif"; } elseif ($klok_dec >= "51" AND $klok_dec <= "75") { $klok_dec ="75"; $klok_dec_image = "klok_4-3.gif"; } elseif ($klok_dec >= "76" AND $klok_dec <= "99") { $klok_dec ="0"; $klok_dec_image = "klok_4-0.gif"; --$klok_int; } else { $klok_dec ="ERROR"; $klok_dec_image = "ERROR"; } ?> -- Raquel ============================================================ Remember that nobody will ever get ahead of you as long as he is kicking you in the seat of the pants. --Walter Winchell

« previous php.db (#13206) next »