Basically I want a client to tick a radio button, which will then return the value of 1 to the database field PROMO. It's so that they can promote a course on the home page when ticked, out of all courses available.
The code below shows the PHP gets the course category title then populates a table with the related courses, then gets the next category and so on. There is one database table for all the courses, which has a PROMO field set by default to zero.
The issue I'm having is the very last radio button is always passed to the database and not the one activated. Is there a way of registering which button has been ticked ONLY? Can this be done with PHP or will it need to be Javascript using onclick?
I'd like to use radio buttons, as the client MUST ONLY tick one box. I tried using name="CSCode[i]" and name="Promo[i]" giving each field a unique number, but then it was letting me tick multiple radio buttons as the names were all different i.e. name="Promo0(1) ", name="Promo1(1) ", name="Promo2(1) " etc. The name of the radio button must be the same in order for only one selection to be used.
Any help would be most grateful.
Cheers
Glynn
The code below shows the PHP gets the course category title then populates a table with the related courses, then gets the next category and so on. There is one database table for all the courses, which has a PROMO field set by default to zero.
Code:
<?php while ($EmptyPrint = mysql_fetch_array($EmptyQuery)){
$CatQuery = mysql_query ("SELECT CSCatCode, CSCatTitle FROM CoursesCat WHERE CSCatCode=".$EmptyPrint['CSCatCode']);
$CatPrint = mysql_fetch_array($CatQuery);?>
<h3><?php echo $CatPrint['CSCatTitle'] ?> Courses</h3>
<table id="TBAmends">
<tr class="Headers">
<th class="Head1">Course – Date</th>
<th class="Head2">Promote</th>
</tr>
<?php $TBQuery = mysql_query ("SELECT CSCode, CSTitle, date_format(CSDate, '%d %M %Y') AS RealDate, CSOrder, Promo FROM Courses WHERE CSCatCode = ".$CatPrint['CSCatCode']." ORDER BY CSDate");
while ($TBPrint = mysql_fetch_array($TBQuery)) { ?>
<tr>
<td class="cmsname"><?php echo $TBPrint['CSTitle']; ?> – <?php echo $TBPrint['RealDate']; ?></td>
<td class="cmsedit"><input type="hidden" name="CSCode" value="<? echo $TBPrint['CSCode']; ?>" /><input type="radio" <?php $flag = false;
if($TBPrint['Promo'] == 1){
$flag = true;}
if($flag) echo "checked=\"checked\""; ?>
name="Promo" id="Promo" value="1" /></td>
</tr>
<?php } ?>
</table>
<?php } ?>
I'd like to use radio buttons, as the client MUST ONLY tick one box. I tried using name="CSCode[i]" and name="Promo[i]" giving each field a unique number, but then it was letting me tick multiple radio buttons as the names were all different i.e. name="Promo0(1) ", name="Promo1(1) ", name="Promo2(1) " etc. The name of the radio button must be the same in order for only one selection to be used.
Any help would be most grateful.
Cheers
Glynn
Comment