繁体   English   中英

使用php和oracle 11g显示一个ID的多个数据

[英]Show multiple data with one id using php and oracle 11g

这是我的查询,用于查看表格问题中的question_id和问题以及表格答案中的4个多项选择答案。

    select q.question,q.question_id,a.answer from questions q, answers a where q.question_id=a.question_id;

我得到的结果如下所示,

    question_id   question   answer
    --------------------------------
       65          1+2=         2
       65          1+2=         4
       65          1+2=         3
       65          1+2=         1
     --------------------------------

实际上我需要我的数据,如下所示:

    question_id   question   answer
    --------------------------------
       65          1+2=         2
                                4
                                3
                                1
     --------------------------------

谁能帮我解决这个问题? 以下是我的php代码,

    <?php

    $conn = oci_connect("username", "password", "orcl");

$f=1;   
$sql1="select q.question,q.question_id,a.answer from questions q, answers a     where q.question_id=a.question_id and q.question_id='63'";
$result2=oci_parse($conn, $sql1);
oci_execute($result2); 
?> 
<title>e-TUITION</title>
<body>
<br>
    <table width="800" height="100" align="center" border="1" bgcolor="">
     <tr bgcolor = "">
        <td colspan="9" bgcolor=""><div align="center"><font face="Times New     Roman"color=""><strong> Question : 
        </strong></font></div>
        </td>
     </tr>
<tr>
<td width="13"><b>Question_ID</td>
<td width="38"><b>Question</td>
<td width="38"><b>Answer</td>
</tr>


<?php
if ($result2)
{
while ($row = oci_fetch_assoc ($result2))
{
?>
<tr>
<td><?php echo $row ["QUESTION_ID"];?></td>
<td><?php echo $row ["QUESTION"];?></td>
<td><input type="CHECKBOX" name="food"  value="ANSWER"> <?php echo $row ["ANSWER"];?></td>
</tr>   
<?php } ?>
<?php } ?>
</table>

我已经重写了显示数据的代码片段

$empty_if_same = array("QUESTION_ID", "QUESTION");
while ($row = oci_fetch_assoc ($result2))
{
    $row1 = $row;
    if (isset($prev_row))
    {
        foreach($empty_if_same as $key)
        {
            if ($prev_row[$key] == $row[$key])
            {
                $row1[$key] = "";
            }
        }
    }
    ?>
    <tr>
        <td><?php echo $row1["QUESTION_ID"];?></td>
        <td><?php echo $row1["QUESTION"];?></td>
        <td><input type="CHECKBOX" name="food"  value="ANSWER"> <?php echo $row1["ANSWER"];?></td>
    </tr>
<?php
    $prev_row = $row;
}
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM