FooKelvin Posted January 19, 2016 Share Posted January 19, 2016 (edited) Hello, I currently have two tables. question and question_option table. each question might have more than one question_option. Here is my excel sheet. https://onedrive.live.com/edit.aspx?cid=b28ee3cd15a16520&page=view&resid=B28EE3CD15A16520!1937&parId=B28EE3CD15A16520!1932&app=Excel So, here is my php code: $conn = sqlsrv_connect($serverName, $connectionInfo); $data = array(); $trows = ''; $sql = " SELECT q.[question_id], q.[q_text],qopt.[option_label],qopt.[opt_text] FROM [RSA].[dbo].[question] q LEFT JOIN [RSA].[dbo].[question_options] qopt ON q.[question_id]=qopt.[question_id] ORDER BY [question_id] ASC"; $stmt = sqlsrv_query($conn, $sql); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } while (list($qid, $qtxt, $qoptlabel, $qopttxt) = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) { if (!isset($data[$qid])) { $data[$qid]['question_id'] = $qid; $data[$qid]['q_text'] = $qtxt; //$data[$qid]['option_label'] = $qoptlabel; //$data[$qid]['opt_text'] = $qopttxt; } } foreach ($data as $qid => $qdata) { $trows .= "<tr><td class='cn'>{$qdata['question_id']}</td>" . "<td>{$qdata['q_text']}</td>"; //. "<td>{$cdata['option_label']}</td>" //. "<td>{$cdata['opt_text']}</td>"; foreach ($qdata as $option) { $trows .= "<td class='dt'>{$option['$qopttxt']}</td>"; } $trows .= "</tr>\n"; } ?> <table border='1'> <?php echo $trows?> </table> I able to for each all the question, but i have stuck over the option value there. The option value most of them is check boxes. Edited January 19, 2016 by FooKelvin 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.