For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2006 > Ticking a check box based on a value from a record









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Ticking a check box based on a value from a record
Ian Davies

2006-05-27, 6:57 pm

Hello
I am retreiving records into a table (part of the code below)

<td width="20%" class="BodyText"><span class="style38"><?php echo
$commindex; ?></span></td>
<td width="10%" class="BodyText"><span class="style38"><?php echo
$username; ?></span></td>
<td width="45%" class="BodyText"><span class="style38"><?php echo
$comment; ?></span></td>
<td width="10%" class="BodyText"><span class="greenbody">
<input name="checkbox2" type="checkbox" value="<?php echo <td
width="20%" class="BodyText"><span class="style38"><?php echo $commindex;
?></span></td>
<td width="10%" class="BodyText"><span class="style38"><?php echo
$username; ?></span></td>
<td width="45%" class="BodyText"><span class="style38"><?php echo
$comment; ?></span></td>
<td width="10%" class="BodyText"><span class="greenbody">
<input name="checkbox2" type="checkbox" value="<?php echo
$available; ?>" MYFUNCTIONHERE>
</span></td>; ?>">
</span></td>


The last cell contains a check box, its value is set to $available. which is
a value of 1 or 0.
Trouble is I want the check box to be ticked if the value is 1 and unticked
if the value is 0
I thought of using a function such as

function checked($avail) {
if ($avail = $available) {
return 'checked';
}
}

after the value part of the code (where I have written MYFUNCTIONHERE)
which would put the work 'checked' in the appropriate place
but my inexperience means I cant get the syntax correct

can anyone help

Ian


Ian Davies

2006-05-27, 6:57 pm

Ignore my question I just found it

if($available == 1){echo " CHECKED";}

Thanks for your time
Ian

"Ian Davies" <iandan.dav@virgin.net> wrote in message
news:JH2eg.2661$zv2.1351@newsfe4-gui.ntli.net...
> Hello
> I am retreiving records into a table (part of the code below)
>
> <td width="20%" class="BodyText"><span class="style38"><?php echo
> $commindex; ?></span></td>
> <td width="10%" class="BodyText"><span class="style38"><?php echo
> $username; ?></span></td>
> <td width="45%" class="BodyText"><span class="style38"><?php echo
> $comment; ?></span></td>
> <td width="10%" class="BodyText"><span class="greenbody">
> <input name="checkbox2" type="checkbox" value="<?php echo <td
> width="20%" class="BodyText"><span class="style38"><?php echo $commindex;
> ?></span></td>
> <td width="10%" class="BodyText"><span class="style38"><?php echo
> $username; ?></span></td>
> <td width="45%" class="BodyText"><span class="style38"><?php echo
> $comment; ?></span></td>
> <td width="10%" class="BodyText"><span class="greenbody">
> <input name="checkbox2" type="checkbox" value="<?php echo
> $available; ?>" MYFUNCTIONHERE>
> </span></td>; ?>">
> </span></td>
>
>
> The last cell contains a check box, its value is set to $available. which

is
> a value of 1 or 0.
> Trouble is I want the check box to be ticked if the value is 1 and

unticked
> if the value is 0
> I thought of using a function such as
>
> function checked($avail) {
> if ($avail = $available) {
> return 'checked';
> }
> }
>
> after the value part of the code (where I have written MYFUNCTIONHERE)
> which would put the work 'checked' in the appropriate place
> but my inexperience means I cant get the syntax correct
>
> can anyone help
>
> Ian
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com