southern_lady_anita
New Member
Below I have 2 sql queries, one to select question details for each question and the other to select the images displayed:\[code\]$qandaquery = "SELECT q.QuestionContent, ptionType, q.NoofAnswers, GROUP_CONCAT( DISTINCT AnswerORDER BY AnswerSEPARATOR ' ' ) AS Answer, r.ReplyType, q.QuestionMarksFROM Question qLEFT JOIN Answer an ON q.QuestionId = an.QuestionIdLEFT JOIN Reply r ON q.ReplyId = r.ReplyIdLEFT JOIN Option_Table o ON q.OptionId = ptionIdWHERE SessionId = ?GROUP BY q.QuestionIdORDER BY q.QuestionId";global $mysqli;$qandaqrystmt=$mysqli->prepare($qandaquery);// You only need to call bind_param once$qandaqrystmt->bind_param("i",$_POST["session"]);// get result and assign variables (prefix with db)$qandaqrystmt->execute(); $qandaqrystmt->bind_result($qandaQuestionContent,$qandaOptionType,$qandaNoofAnswers,$qandaAnswer,$qandaReplyType,$qandaQuestionMarks);$arrQuestionContent = array();$arrOptionType = array();$arrNoofAnswers = array();$arrAnswer = array();$arrReplyType = array();$arrQuestionMarks = array();while ($qandaqrystmt->fetch()) { $arrQuestionContent[] = $qandaQuestionContent; $arrOptionType[] = $qandaOptionType; $arrNoofAnswers[] = $qandaNoofAnswers; $arrAnswer[] = $qandaAnswer; $arrReplyType[] = $qandaReplyType; $arrQuestionMarks[] = $qandaQuestionMarks;}$qandaqrystmt->close();$imgquery = "SELECT s.SessionId, q.QuestionId, i.ImageId, ImageFile FROM Session s INNER JOIN Question q ON s.SessionId = q.SessionId INNER JOIN Image_Question iq ON q.QuestionId = iq.QuestionId INNER JOIN Image i ON iq.ImageId = i.ImageId WHERE s.SessionId = ?";global $mysqli;$imgqrystmt=$mysqli->prepare($imgquery);// You only need to call bind_param once$imgqrystmt->bind_param("i",$_POST["session"]);// get result and assign variables (prefix with db)$imgqrystmt->execute(); $imgqrystmt->bind_result($imgSessionId,$imgQuestionId,$imgImageId,$imgImageFile);$arrImgQuestionId = array();$arrImageFile = array();while ($imgqrystmt->fetch()) { $arrImgQuestionId[] = $imgQuestionId; $arrImageFile[] = $imgImageFile;}$imgqrystmt->close();\[/code\]The issue I am having is when I try to display the details if the images for each question. Each question could have either 0 images, one image or multiple images.But the problem I am receiving is that if a question does not contain an image, it comes out with this error below:\[code\]Notice: Undefined offset: 0 inNotice: Undefined offset: 1 in....Notices displaying in each question row which does not contain an image.\[/code\]I also have another little problem where if a question has multiple images, in the table it only displays one image for the question, not all the images.How can the notices be fixed and get multiple images to be displayed in question rows which contains multiple images?Below is the table:\[code\] <table id="tableqanda" align="center" cellpadding="0" cellspacing="0"> <thead> <tr> <th width="30%" class="question">Question</th> <th width="8%" class="option">Option Type</th> <th width="6%" class="noofanswers">Number of Answers</th> <th width="8%" class="answer">Answer</th> <th width="6%" class="noofreplies">Number of Replies</th> <th width="6%" class="noofmarks">Number of Marks</th> <th width="12%" class="images">Images</th> </tr> </thead> </table> <div id="tableqanda_onthefly_container"> <table id="tableqanda_onthefly" align="center" cellpadding="0" cellspacing="0"> <tbody> <?php foreach ($arrQuestionContent as $key=>$question) { echo '<tr class="tableqandarow">'.PHP_EOL; echo '<td width="30%" class="question">'.htmlspecialchars($question).'</td>' . PHP_EOL; echo '<td width="8%" class="option">'.htmlspecialchars($arrOptionType[$key]).'</td>' . PHP_EOL; echo '<td width="6%" class="noofanswers">'.htmlspecialchars($arrNoofAnswers[$key]).'</td>' . PHP_EOL; echo '<td width="8%" class="answers">'.htmlspecialchars($arrAnswer[$key]).'</td>' . PHP_EOL; echo '<td width="6%" class="noofreplies">'.htmlspecialchars($arrReplyType[$key]).'</td>' . PHP_EOL; echo '<td width="6%" class="noofmarks">'.htmlspecialchars($arrQuestionMarks[$key]).'</td>' . PHP_EOL; echo '<td width="12%" class="images">'.htmlspecialchars($arrImageFile[$key]).'</td>' . PHP_EOL; /*Notices are appearing in above line*/ echo '</tr>'.PHP_EOL; } ?> </tbody> </table>\[/code\]