如何从查询中选择的表中停止循环?

时间:2016-03-08 02:27:56

标签: php mysql sql

image

大家好。我想问一下如何最小化第二张桌子?

因为我想它只是打印一次没有循环,但我希望所有的值与第一个表

进行比较

这是我的代码

<?php 
                    $query1 = mysql_query("SELECT * FROM training_detail AS s JOIN subject AS t JOIN training AS u JOIN employee AS v WHERE v.id_employee = $id1 AND s.nik LIKE v.nik AND u.id_subject LIKE t.id_subject AND s.id_training LIKE u.id_training ");
                    $i=1;
                    while($row1 = mysql_fetch_array($query1))
                    {
                        $date = $row1['date'];
                        $subject1 = $row1['subject_name'];
                ?>
            <table class="table table-bordered">
                <tr>
                    A
                    <td class="table-bordered">No</td>
                    <td class="table-bordered">date</td>
                    <td class="table-bordered">subject</td>
                    <td class="table-bordered">subject no</td>
                    <td class="table-bordered">revision no</td>
                    <td class="table-bordered">Trainer</td>
                    <td class="table-bordered">Institution</td>
                </tr>

                <tr>
                    <td class="table-bordered"><?php echo $i; ?></td>
                    <td class="table-bordered"><?php echo date("j/F/Y", strtotime($date)); ?></td>
                    <td class="table-bordered"><?php echo $subject1; ?></td>
                    <td class="table-bordered"><?php echo $row1['subject_no']; ?></td>
                    <td class="table-bordered"><?php echo $row1['revision_no']; ?></td>
                    <td class="table-bordered"><?php echo $row1['trainer']; ?></td>
                    <td class="table-bordered"><?php echo $row1['institution']; ?></td> 
                </tr>

            </br>
            <table class="table table-bordered">
                <tr>
                    B
                    <td class="table-bordered">No</td>
                    <td class="table-bordered">subject</td>
                    <td class="table-bordered">subject name</td>
                    <td class="table-bordered">subject no</td>
                </tr>
                <?php 
                    $query2 = mysql_query("SELECT * FROM header_job AS r JOIN subject AS q JOIN employee AS p WHERE q.id_subject LIKE r.id_header AND r.id_job LIKE  p.id_job AND p.id_employee = $id1 ORDER BY q.id_subject ASC ");
                    $x=1;
                    while($row2 = mysql_fetch_array($query2))
                    {
                        $subject2 = $row2['subject_name'];
                        if (strcasecmp($subject1, $subject2) != 0) 
                        {
                ?>
                <tr>
                    <td class="table-bordered"><?php echo $i; ?></td>
                    <td class="table-bordered"><?php echo $row2['subject'] ?></td>
                    <td class="table-bordered"><?php echo $subject2; ?></td>
                    <td class="table-bordered"><?php echo $row2['subject_no']; ?></td>
                </tr>     
                <?php  


                        }
                    $x++;       
                    }
                    $i++;
                }

                ?>
            </table>
        </table>
抱歉,我的照片是我自己的语言

1 个答案:

答案 0 :(得分:0)

如果你想最小化输出

尝试使用限制

像这样:

$query2 = mysql_query("SELECT * FROM header_job AS r JOIN subject AS q JOIN employee AS p WHERE q.id_subject LIKE r.id_header AND r.id_job LIKE p.id_job AND p.id_employee = $id1 ORDER BY q.id_subject ASC limit 1");