Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Mon Mar 22, 2004 11:12 am
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ї'active']; ?>">
The checkbox does not display a check at all. I want it to.
penguinboy
Forum Contributor
Posts: 171 Joined: Thu Nov 07, 2002 11:25 am
Post
by penguinboy » Mon Mar 22, 2004 11:37 am
Code: Select all
<input name="active" type="checkbox" id="active" value="1" <?php echo ($row_articleEDITї'active']==1)?'checked="checked"':''; ?> />
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Mon Mar 22, 2004 11:54 am
That worked! Thanks.
thurstan
Forum Commoner
Posts: 28 Joined: Mon Feb 28, 2005 7:40 am
Post
by thurstan » Tue Mar 22, 2005 9:47 am
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
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 22, 2005 9:52 am
all you need is inserting the ternary properly.. that's it..
Code: Select all
echo '<input name="e;offerstartdate"e; type="e;text"e; id="e;offerstartdate"e; value="e;' . $rowї'offsetstartdate'] . '"e;' . ($rowї'onoffer'] == 1 ? ' checked="e;checked"e;' : '') . ' />';
thurstan
Forum Commoner
Posts: 28 Joined: Mon Feb 28, 2005 7:40 am
Post
by thurstan » Tue Mar 22, 2005 10:02 am
excellent - thanks very much feyd. must read up on 'ternary'