I am trying to run a simple PHP script that connects to a MySQL database that has rows a-z, an id, and answer. I want to check if a-z has something in it then display a radiobox if it does and if for example a = z then the radiobox is checked. Since I am going through and checking for every letter for some reason it always puts the last letter displayed as the checked even though it's not always that as the answer.
example code:
$answ = $row8['answer'];
if($row8['a'] == $answ) {$checkda = "yes";}
elseif($row8['b'] == $answ) {$checkdb = "yes";}
elseif($row8['c'] == $answ) {$checkdc = "yes";}
elseif("4" == $answ) {$checkdd = "yes";}
elseif("5" == $answ) {$checkde = "yes";}
elseif("6" == $answ) {$checkdf = "yes";}
elseif("7" == $answ) {$checkdg = "yes";}
elseif("8" == $answ) {$checkdh = "yes";}
elseif("9" == $answ) {$checkdi = "yes";}
elseif("10" == $answ) {$checkdj = "yes";}
elseif("11" == $answ) {$checkdk = "yes";}
elseif("12" == $answ) {$checkdl = "yes";}
elseif("13" == $answ) {$checkdm = "yes";}
elseif("14" == $answ) {$checkdn = "yes";}
elseif("15" == $answ) {$checkdo = "yes";}
elseif("16" == $answ) {$checkdp = "yes";}
elseif("17" == $answ) {$checkdq = "yes";}
elseif("18" == $answ) {$checkdr = "yes";}
elseif("19" == $answ) {$checkds = "yes";}
elseif("20" == $answ) {$checkdt = "yes";}
elseif("21" == $answ) {$checkdu = "yes";}
elseif("22" == $answ) {$checkdv = "yes";}
elseif("23" == $answ) {$checkdw = "yes";}
elseif("24" == $answ) {$checkdx = "yes";}
elseif("25" == $answ) {$checkdy = "yes";}
elseif("26" == $answ) {$checkdz = "yes";}
if($row8['a'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['a']."' id='_".$row8['id']."' checked='".$checkda."' />".$row8['a']."</label><br />";}
if($row8['b'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['b']."' id='_".$row8['id']."' checked='".$checkdb."' />".$row8['b']."</label><br />";}
if($row8['c'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['c']."' id='_".$row8['id']."' checked='".$checkdc."' />".$row8['c']."</label><br />";}
if($row8['d'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['d']."' id='_".$row8['id']."' checked='".$checkdd."' />".$row8['d']."</label><br />";}
if($row8['e'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['e']."' id='_".$row8['id']."' checked='".$checkde."' />".$row8['e']."</label><br />";}
if($row8['f'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['f']."' id='_".$row8['id']."' checked='".$checkdf."' />".$row8['f']."</label><br />";}
EDIT: In the first set of code I have both "4" == $answ as well as $row8['b']
Not trying to confuse on the irregularities there but I have tried both ways all the way through and neither worked.
example code:
$answ = $row8['answer'];
if($row8['a'] == $answ) {$checkda = "yes";}
elseif($row8['b'] == $answ) {$checkdb = "yes";}
elseif($row8['c'] == $answ) {$checkdc = "yes";}
elseif("4" == $answ) {$checkdd = "yes";}
elseif("5" == $answ) {$checkde = "yes";}
elseif("6" == $answ) {$checkdf = "yes";}
elseif("7" == $answ) {$checkdg = "yes";}
elseif("8" == $answ) {$checkdh = "yes";}
elseif("9" == $answ) {$checkdi = "yes";}
elseif("10" == $answ) {$checkdj = "yes";}
elseif("11" == $answ) {$checkdk = "yes";}
elseif("12" == $answ) {$checkdl = "yes";}
elseif("13" == $answ) {$checkdm = "yes";}
elseif("14" == $answ) {$checkdn = "yes";}
elseif("15" == $answ) {$checkdo = "yes";}
elseif("16" == $answ) {$checkdp = "yes";}
elseif("17" == $answ) {$checkdq = "yes";}
elseif("18" == $answ) {$checkdr = "yes";}
elseif("19" == $answ) {$checkds = "yes";}
elseif("20" == $answ) {$checkdt = "yes";}
elseif("21" == $answ) {$checkdu = "yes";}
elseif("22" == $answ) {$checkdv = "yes";}
elseif("23" == $answ) {$checkdw = "yes";}
elseif("24" == $answ) {$checkdx = "yes";}
elseif("25" == $answ) {$checkdy = "yes";}
elseif("26" == $answ) {$checkdz = "yes";}
if($row8['a'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['a']."' id='_".$row8['id']."' checked='".$checkda."' />".$row8['a']."</label><br />";}
if($row8['b'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['b']."' id='_".$row8['id']."' checked='".$checkdb."' />".$row8['b']."</label><br />";}
if($row8['c'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['c']."' id='_".$row8['id']."' checked='".$checkdc."' />".$row8['c']."</label><br />";}
if($row8['d'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['d']."' id='_".$row8['id']."' checked='".$checkdd."' />".$row8['d']."</label><br />";}
if($row8['e'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['e']."' id='_".$row8['id']."' checked='".$checkde."' />".$row8['e']."</label><br />";}
if($row8['f'] != "") { echo "<label><input type='radio' name='".$row8['id']."' value='".$row8['f']."' id='_".$row8['id']."' checked='".$checkdf."' />".$row8['f']."</label><br />";}
EDIT: In the first set of code I have both "4" == $answ as well as $row8['b']
Not trying to confuse on the irregularities there but I have tried both ways all the way through and neither worked.