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.
Expand|Select|Wrap|Line Numbers
- <?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