checkbox problem (checked/unchecked)
Posted: Wed Feb 03, 2010 3:07 pm
hi i have a web form for user to sell their used cars online. in the form a section contains the "Features" of the car. which i collect through check boxes like the give code below
user will check those check boxes which features his car have.
i save all these features in a single field separated with (,). example (Air Bags, Power Windows, Cruise Control, Power Mirror)
the features save query is given below
all these works fine. now the problem is that i used this form also for edit/update entry.
mean if user want to edit his existing entry , he will again use this form.
i passed a query to check if the url contains an id with form it will display the existing values otherwise it will displays blank value.
to get the record of the existing entry i used this command
this query collects records from database fine.
i want that it check in the "features" field for values,
if it got some values like (Air Bags, Power Windows, Cruise Control, Power Mirror).
the check boxes of these values should be checked.
mean the check box of Air Bags should be checked,
mean the check box of Power Windows should be checked ...so on
is there anyway to control it?
Thanks in advance for help
Code: Select all
<table border="0" cellpadding="0" cellspacing="0" width="450">
<tbody><tr>
<td width="150">
<input name="Features[]" id="AirBags" value="Air Bags" type="checkbox"> Air Bags</td>
<td width="150"><input name="Features[]" id="AirConditioning" value="Air Conditioning" type="checkbox"> Air Conditioning</td>
<td width="150"><input name="Features[]" id="PowerWindows" value="Power Windows" type="checkbox"> Power Windows</td>
</tr>
<tr>
<td width="150"><input name="Features[]" id="PowerSteering" value="Power Steering" type="checkbox"> Power Steering</td>
<td width="150"><input name="Features[]" id="PowerLocks" value="Power Locks" type="checkbox"> Power Locks</td>
<td width="150"><input name="Features[]" id="PowerMirror" value="Power Mirror" type="checkbox"> Power Mirror</td>
</tr>
<tr>
<td width="150"><input name="Features[]" id="KeyLessEntry" value="Keyless Entry" type="checkbox"> Keyless Entry</td>
<td width="150"><input name="Features[]" id="CruiseControl" value="Cruise Control" type="checkbox"> Cruise Control</td>
<td width="150"><input name="Features[]" id="NavigationSystem" value="Navigation System" type="checkbox"> Navigation System</td>
</tr>
</tbody></table>i save all these features in a single field separated with (,). example (Air Bags, Power Windows, Cruise Control, Power Mirror)
the features save query is given below
Code: Select all
$features = $_REQUEST['Features'];
$xCount = count($features);
$catStr = "";
for($i = 0; $i < $xCount; $i++){
$catStr = $catStr.$features[$i].", ";
}
$catLen = strlen($catStr);
$catStr = str_split($catStr, $catLen-2);
$catStr = $catStr[0];mean if user want to edit his existing entry , he will again use this form.
i passed a query to check if the url contains an id with form it will display the existing values otherwise it will displays blank value.
to get the record of the existing entry i used this command
Code: Select all
"SELECT * FROM usedcars WHERE carid = 6"this query collects records from database fine.
i want that it check in the "features" field for values,
if it got some values like (Air Bags, Power Windows, Cruise Control, Power Mirror).
the check boxes of these values should be checked.
mean the check box of Air Bags should be checked,
mean the check box of Power Windows should be checked ...so on
Thanks in advance for help