Page 1 of 1

Checkbox Issue

Posted: Mon Mar 22, 2004 11:12 am
by AliasBDI
I have an UPDATE page using PHP/MySQL. The form works fine, but a check box does not display the record. The field it is pulling is CHAR, 1 digit, and the record is either "1" or "0". If it is "1" it should have the checkbox checked. Here is my check box code:

Code: Select all

<input name="active" type="checkbox" id="active" value="<?php echo $row_articleEDIT&#1111;'active']; ?>">
The checkbox does not display a check at all. I want it to.

Posted: Mon Mar 22, 2004 11:37 am
by penguinboy

Code: Select all

<input name="active" type="checkbox" id="active" value="1" <?php echo ($row_articleEDIT&#1111;'active']==1)?'checked="checked"':''; ?> />

thanks.

Posted: Mon Mar 22, 2004 11:54 am
by AliasBDI
That worked! Thanks.

Posted: Tue Mar 22, 2005 9:47 am
by thurstan
this also works very nicely for me:

Code: Select all

<input name="onoffer" type="checkbox" id="onoffer" value="1" <?php echo ($row['onoffer']==1)?'checked="checked"':''; ?> />
but, i need to insert this into code already warpped in php tags, ie:

Code: Select all

echo"<br /><br />What is the offer start date?<br />";
echo"<input name=\"offerstartdate\" type=\"text\" id=\"offerstartdate\" value=\"" .$row["offerstartdate"]. "\" />";

echo"<br /><br />What is the offer price?<br />";
echo"<input name=\"offerprice\" type=\"text\" id=\"offerprice\" value=\"" .$row["offerprice"]. "\" />";
every time i try to do this i get an error - i just can't seem to get the correct combination of "'s and .'s - can anybody help? thank you v much.


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Mar 22, 2005 9:52 am
by feyd
all you need is inserting the ternary properly.. that's it..

Code: Select all

echo '&lt;input name=&quote;offerstartdate&quote; type=&quote;text&quote; id=&quote;offerstartdate&quote; value=&quote;' . $row&#1111;'offsetstartdate'] . '&quote;' . ($row&#1111;'onoffer'] == 1 ? ' checked=&quote;checked&quote;' : '') . ' /&gt;';

Posted: Tue Mar 22, 2005 10:02 am
by thurstan
excellent - thanks very much feyd. must read up on 'ternary'