PDA

View Full Version : filling in check boxes from a database


davehaz
05-15-2006, 09:38 PM
howdy,
working on a form, need to know how to fill in a series of check boxes for an update page from a database. I have the text boxes filling in like this

<input name="merchant_name" type="text" value="<? echo $merchant_name; ?>" onClick="value=''">

but that wont work on a check box.

tia.

goughy000
05-15-2006, 09:44 PM
what is your aim?

How are the values stored in the database? 1 for checked and 0 for blank? or what?

davehaz
05-15-2006, 09:54 PM
y for checked
empty for not checked

I am trying to fillin the the check boxes as they were entered into the db, so that the person updating the page can then go and check missing boxes or uncheck as the need occurs.

Philipp
05-15-2006, 10:27 PM
hm.. may like this?

for ($i=0;$i< (NUMBER OF ROWS);$i++){
echo '<input type="checkbox" name="grnr['.$i.']" value="';
if ($value[$i]=="y")
echo '1';
echo '">';
}

davehaz
05-15-2006, 11:33 PM
thanks for the help but I went this way,

<? if($travel =='y') {echo "<input type='checkbox' name='travel' value='y' checked >";} else {echo "<input type='checkbox' name='travel' value='y' >";} ?>

lavinpj1
05-15-2006, 11:35 PM
Not the best way to do it. Philipp had the right idea, but had the html wrong.

~Phil~

davehaz
05-15-2006, 11:53 PM
just out of curiosity, why is one better than the other?

Philipp
05-16-2006, 08:21 AM
Not the best way to do it. Philipp had the right idea, but had the html wrong.

what's wrong?
i tested it now and it works fine.


just out of curiosity, why is one better than the other?
If you have to change the code of the checkboxes, for example the css-class or what ever, there is only one place to change instead of many. that's easier if the code is readable :rolleyes:

MRMAN
05-16-2006, 09:37 AM
i'd do this


<input type='checkbox' name='travel' value='y' <? if($travel =='y') {echo "checked=\"checked\"";} ?>>

Philipp
05-16-2006, 10:05 AM
ubs.
yes - shure :)