passed val compare to array val
| From: | sundogcurt | Date: | Fri, 12 Apr 2002 18:16:48 +0000 |
| Subject: | passed val compare to array val | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-92800@lists.php.net to get a copy of this message | ||
Hi guys, like every other problem I have this one is SURE to be painfully simple to fix and make me look g0ofy again.
I have an edit user form with checkboxes like the one below :
<INPUT type="checkbox" value="Boating" name="Activity[]" <?docheck("Boating")?>>
When the form loads I grab the users relevant information and display it, I am having trouble checking checkboxes that should be checked though. Here is how I am attempting to do it.
Prior to the form loading I load an array with the required checkbox VALUES, not names, I did it this way because I reference the checkbox values as an array to write to a database.
As the form loads I call a function "docheck()" and pass $inputvalue (the value of the checkbox) compare the values pulled from the database and if there is a match, I write "CHECKED" to indicate that the user had previously chosen this.
The function is below :
function docheck($inputvalue){
$flag = 0;
$tempcnt = 0;
$temptotal = count($editActivity);
while($tempcnt != $temptotal){
if($inputvalue == $editActivity[$tempcnt]){
$flag = 1;
}
$tempcnt++;
}
if($flag == 1){
print "CHECKED";} } The problem seems to be that a "match" never occurs, I tried passing "Boating" and re-wrote the function as such... $flag = 0; if($inputvalue == 'Boating'){ $flag = 1; } if($flag == 1){ print "CHECKED"; } and it worked just fine, so I am of a mind that I am doing something wrong while attempting to match my passed value with the values in my array. Please help! -- Curtis Gordon Groovy Web Developer xxxx 168th Street White Rock