Forum Moderators: coopster

Message Too Old, No Replies

Populating Checkboxes from a MySQL Database

         

theriddla1019

5:48 pm on Jan 7, 2004 (gmt 0)

10+ Year Member



Here is the code, what im doing is populating a php variable, and trying to use the result to add either checked or nothing to the value of the checkbox. Any ideas?

:Example of the sql string populating the variable

$FLAmbulation = $Row['FLAmbulation'];
if ($FLAmbulation == 1)
{
$FLAmbulation = 'checked';
}
else
{
$FLAmbulation = '';
}

:Example of me trying to use the variable to add to the value of the checkbox.

<div style="position: absolute; left:57px; top:444px; width:86px; height:13px;">
<table width=86px height=13px border=0 cellpadding=0 cellspacing=0><tr><td valign=top align=left>

<p id=PubSt1P><span id=PubSt1F>Contracture<br></span></p>

</td></tr></table>
</div>
<div id=div414 style="position: absolute; left:36px; top:444px; width:21px; height:13px;">
<input type="checkbox" name="CHECK_BOX_3" value="Yes"
<? $FLContracture?>;>

</div>
<div id=div419 style="position: absolute; left:57px; top:456px; width:86px; height:13px;">
</div>

Please help!
Riddla

jatar_k

5:55 pm on Jan 7, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld theriddla1019,

try this

$FLAmbulation = '';
if ($Row['FLAmbulation'] == 1) $FLAmbulation = ' checked';

I added a space before checked and shortened it up a bit

<input type="checkbox" name="CHECK_BOX_3" value="Yes"<?= $FLContracture?>>

the <?= is the shorthand for echoing a variable. You aren't actually outputting the value in the example you gave.

dreamcatcher

6:13 pm on Jan 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can also use something like:

echo "<input type=\"checkbox\"".(($Row['FLAmbulation'])? " checked" : "")." name=\"CHECK_BOX_3\" value=\"Yes\">\n";

:)

theriddla1019

7:08 pm on Jan 7, 2004 (gmt 0)

10+ Year Member



Perfect!
Thanks yall :)