phpretard Posted August 3, 2009 Share Posted August 3, 2009 If there are no answers in the DB it should read "No Answers Assigned" Can anyone see why it would just show up blank? The rest works fine ... if there are answers while($all=mysql_fetch_assoc($all_answers)) { $answer[]=$all['answer']; foreach($answer as $checkbox) { if (empty($answer)){ $answer_list = "<input type=\"checkbox\" disabled /> <font size=\"2\">No Answer Asigned</font><br />"; }else{ $answer_list = "<input type=\"checkbox\" name=\"answer\" value=\"".$all['id']."\" /> <font size=\"2\">".$all['answer']."</font><br />"; } } echo $answer_list; } //For the record it is properly indented in the code. The forum didn't indent for some reason. Thank you for looking! Quote Link to comment Share on other sites More sharing options...
WolfRage Posted August 3, 2009 Share Posted August 3, 2009 Don't you need to check prior to the foreach? Quote Link to comment Share on other sites More sharing options...
mattal999 Posted August 3, 2009 Share Posted August 3, 2009 while($all=mysql_fetch_assoc($all_answers)) { $answer[]=$all['answer']; if (empty($answer)) { $answer_list = "<input type=\"checkbox\" disabled /> <font size=\"2\">No Answer Asigned</font><br />"; } else { foreach($answer as $checkbox) { $answer_list = "<input type=\"checkbox\" name=\"answer\" value=\"".$all['id']."\" /> <font size=\"2\">".$all['answer']."</font><br />"; } } echo $answer_list; } //For the record it is properly indented in the code. The forum didn't indent for some reason. Quote Link to comment Share on other sites More sharing options...
phpretard Posted August 3, 2009 Author Share Posted August 3, 2009 Thanks for the quick response but, even the new code gives me a blank... Quote Link to comment Share on other sites More sharing options...
watsmyname Posted August 3, 2009 Share Posted August 3, 2009 Thanks for the quick response but, even the new code gives me a blank... trying changing if(empty($answer)) to if(count($answer)==0) Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 3, 2009 Share Posted August 3, 2009 By blank you mean a completely blank page? Do you have any other output that's supposed to be displayed? If so, chances are you have an error and have display errors turned off. Otherwise, is the while loop even running? Perhaps there are no rows in the result set. Quote Link to comment Share on other sites More sharing options...
phpretard Posted August 3, 2009 Author Share Posted August 3, 2009 Here is the rest of the code: function get_all_answers(){ connect(); $question_id = mysql_query("select id from questions order by RAND() LIMIT 1") or die(mysql_error()); while($id_q = mysql_fetch_assoc($question_id)) { $db_id=$id_q['id']; } $the_question = mysql_query("select question from questions where id = '".$db_id."' ") or die(mysql_error()); while($single_q = mysql_fetch_assoc($the_question)) { echo "<b><font size=\"2\">".$single_q['question']."</font></b><hr />"; } $all_answers=mysql_query("select * from answers where question = '".$db_id."' order by RAND() LIMIT 4") or die(mysql_error()); while($all=mysql_fetch_assoc($all_answers)) { $answer[]=$all['answer']; if (empty($all['answer'])) { $answer_list = "<input type=\"checkbox\" disabled /> <font size=\"2\">No Answer Asigned</font><br />"; } else { foreach($answer as $checkbox) { $answer_list = "<input type=\"checkbox\" name=\"answer\" value=\"".$all['id']."\" /> <font size=\"2\">".$all['answer']."</font><br />"; } } echo $answer_list; } free($question_id); free($the_question); free($all_answers); } Quote Link to comment Share on other sites More sharing options...
watsmyname Posted August 3, 2009 Share Posted August 3, 2009 the simple way to accomplish the thing will be like this <?php $answer=array(); $id=array(); while($all=mysql_fetch_assoc($all_answers)) { array_push($answer,$all['answer']); array_push($id,$all["id"]); } for($i=0;$i<count($answer);$i++) { if(!empty($answer[$i])) { $answer_list = "<input type=\"checkbox\" name=\"answer\" value=\"".$id[$i]."\" /> <font size=\"2\">".$answer[$i]."</font><br />"; }else{ $answer_list = "<input type=\"checkbox\" disabled /> <font size=\"2\">No Answer Asigned</font><br />"; } echo $answer_list; } ?> Quote Link to comment Share on other sites More sharing options...
phpretard Posted August 3, 2009 Author Share Posted August 3, 2009 It still wonn't show "No Answer..." arrg Quote Link to comment Share on other sites More sharing options...
watsmyname Posted August 3, 2009 Share Posted August 3, 2009 It still wonn't show "No Answer..." arrg hmmm try to debug it, try to echo query, copy this and run it in phpmyadmin and see if you get any results. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.