0

I need a fresh start and some fresh ideas.

I get some text from a MySQL database and present like below.

Each row is divided into five columns with radio buttons.

----------------------------------
Text 1-Text 2-Text 3-Text 4-Text 5
Radio1-Radio2-Radio3-Radio4-Radio5
----------------------------------
Text 1-Text 2-Text 3-Text 4-Text 5
Radio1-Radio2-Radio3-Radio4-Radio5
----------------------------------
and so on...

How do I give each radio button an unique name depending on row?

Thankful for any help I can get.

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Peter1
2

How about using a counter in your loop?

<?php
$i=1;
while($i < 6) {
   echo "<input type=\"radio\" name=\"radio$i\" id=\"radio$i\" />";
   $i++;
}
?>

Edited by EvolutionFallen: n/a

Votes + Comments
Helpful! Thank you.
0

Is it possible to do this in a more efficent way?

$sql_huvudrubrik = "SELECT DISTINCT *
														FROM kunskapskrav			
														WHERE amne_id = '".$_GET['amne_id']."'
														ORDER BY kunskapskrav_id ASC
													"; 
						   							
									$result_huvudrubrik = mysql_query($sql_huvudrubrik) or die("Query: $sql_huvudrubrik <br>Error: ".mysql_error());
						   
						   			$finns_huvudrubrik = mysql_num_rows($result_huvudrubrik);
													$i=0;
													while($uppgift_huvudrubrik = mysql_fetch_array($result_huvudrubrik)){ 
														if ($i > 2){$i = 0;}
														$i++;
														$amne_id = $uppgift_huvudrubrik['amne_id'];
														$kunskapstext = $uppgift_huvudrubrik['kunskapstext'];
														$radnummer = $uppgift_huvudrubrik['radnummer'];
														$kunskapstyp = $uppgift_huvudrubrik['kunskapstyp'];
														$kunskapskrav_id = $uppgift_huvudrubrik['kunskapskrav_id'];
														
														if ($i == 1){
															//static columns
														echo "<td class='ramen4'>";
														echo $i."Kravet har ej kunnat uppfyllas då ämnet antingen inte har lästs i den omfattningen att kravet 
														har kunnat prövats.";
														echo "</td>";
														echo "<td class='ramen4'>";
														echo "Eleven uppnår ej kunskapskravet.";
														echo "</td>";
														}
														
														echo "<td class='ramen4'>";
														echo $kunskapstext.'('.$radnummer.':'.$kunskapstyp.')';																										
                                                      
													  	
														echo "</td>";
													
														if ($i == 3){
														echo "</tr>";
														
														
														echo "<tr>";
													
														
														
													?>												
													
													<td class='ramen_special'>
                                                        <input style='margin-right:1.03em;' class='validate-one-required' name='K[
                                                        <?php echo $amne_id.'ID'.$kunskapskrav_id.'RAD'.$radnummer; ?>][]' type='radio' value='0' 
                                                        <?php /*if ($matris_klick == $radio) echo 'checked="checked" ';*/ ?>/>
                                                    </td>
                                                    <td class='ramen_special'>
                                                        <input style='margin-right:1.03em;' class='validate-one-required' name='K[
                                                        <?php echo $amne_id.'ID'.$kunskapskrav_id.'RAD'.$radnummer;?>][]' type='radio' value='1' 
                                                        <?php /*if ($matris_klick == $radio) echo 'checked="checked" ';*/ ?>/>
                                                    </td>
                                                    <td class='ramen_special'>
                                                        <input style='margin-right:1.03em;' class='validate-one-required' name='K[
                                                        <?php echo $amne_id.'ID'.$kunskapskrav_id.'RAD'.$radnummer;?>][]' type='radio' value='2' 
                                                        <?php /*if ($matris_klick == $radio) echo 'checked="checked" ';*/ ?>/>
													</td>
                                                    <td class='ramen_special'>
                                                        <input style='margin-right:1.03em;' class='validate-one-required' name='K[
                                                        <?php echo $amne_id.'ID'.$kunskapskrav_id.'RAD'.$radnummer;?>][]' type='radio' value='3' 
                                                        <?php /*if ($matris_klick == $radio) echo 'checked="checked" ';*/ ?>/>
                                                    </td>
                                                    <td class='ramen_special'>
                                                        <input style='margin-right:1.03em;' class='validate-one-required' name='K[
                                                        <?php echo $amne_id.'ID'.$kunskapskrav_id.'RAD'.$radnummer;?>][]' type='radio' value='4' 
                                                        <?php /*if ($matris_klick == $radio) echo 'checked="checked" ';*/ ?>/>
													</td>
																								
                                                    <?php	
												
												echo "</tr>";
												} 
													}
												?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.