mysqli_fetch_assoc没有清除数组结果重复数据PHP

时间:2015-07-02 04:08:23

标签: php mysql mysqli

我有一个查询,它返回数据库中的不同行,并使用mysqli_fetch_assoc创建结果数组。问题是,当返回结果并显示它们时,数组会将$row数据返回到级联类型效果中的每个唯一DIV。因此,上述结果的结果将永远重复下去。它们相互构建,将前一个结果传递给下面的结果。以下是我的代码片段:

$sql = "select DISTINCT ost_ticket_thread.user_id, ost_ticket_thread.body, ost_ticket_thread.created, ost_ticket_thread.ticket_id, ost_ticket.ticket_id FROM ost_ticket_thread, ost_ticket
 WHERE ost_ticket_thread.user_id = '$user_id'
 AND ost_ticket.ticket_id = ost_ticket_thread.ticket_id
 AND ost_ticket_thread.ticket_id = '$ticket'

 ORDER BY created desc";

 $Rslt = mysqli_query($mysqli,$sql);

while($r=mysqli_fetch_assoc($Rslt))


{
    $res[]=$r;


}

结果如下:

Array
(
[0] => Array
    (
        [user_id] => 13
        [body] => WHATEVEVS!
        [created] => 2015-07-01 19:01:08
        [ticket_id] => 607
    )

[1] => Array
    (
        [user_id] => 13
        [body] => WTF!!!
        [created] => 2015-07-01 19:01:08
        [ticket_id] => 607
    )

[2] => Array
    (
        [user_id] => 13
        [body] => kflsdfkdl
        [created] => 2015-07-01 18:59:16
        [ticket_id] => 607
    )

[3] => Array
    (
        [user_id] => 13
        [body] => WTF
        [created] => 2015-07-01 19:01:10
        [ticket_id] => 606
    )

[4] => Array
    (
        [user_id] => 13
        [body] => Kangertech Subtank
        [created] => 2015-06-24 16:35:06
        [ticket_id] => 606
    )

[5] => Array
    (
        [user_id] => 13
        [body] => TEST UPDATE MT
        [created] => 2015-07-01 18:57:46
        [ticket_id] => 604
    )

[6] => Array
    (
        [user_id] => 13
        [body] => TEST MT 123
        [created] => 2015-07-01 18:57:45
        [ticket_id] => 604
    )

[7] => Array
    (
        [user_id] => 13
        [body] => TESTING NEW TICKET
        [created] => 2015-06-22 21:37:00
        [ticket_id] => 604
    )

[8] => Array
    (
        [user_id] => 13
        [body] => UPDATE NEW TEST TICKET
        [created] => 2015-06-22 19:47:51
        [ticket_id] => 604
    )

[9] => Array
    (
        [user_id] => 13
        [body] => TESTING 123 (NEW TEST TICKET)
        [created] => 2015-06-22 19:14:56
        [ticket_id] => 604
    )

我希望每个结果都显示在自己的DIV中,并且它对于从查询传递的$ticket是唯一的。我希望这是有道理的。

以下是生成DIV的代码:

   $id = uniqid();
   $tid = uniqid();

  // echo "                    <div class=\"panel box box-primary3\">\n";
  // Added MT
  echo          "<a data-toggle=\"collapse\" data-parent=\"#accordion\"           href=\"#$id\" class=\"accordion-toggle\">\n";
echo            "<div class='box-group' id='accordion'>
                <div class='panel box box-ticket-data'>";
// Added MT
echo            "<div class=\"box-header\">\n";

echo            "<div class=\"col-md-1 hidden-xs\">\n";
echo            "<img src=\"$image_status_change\" width=\"50\" style=\"margin-top:15px;margin-left:5px;\"></div>\n";
echo            "<div class='row'><div class=\"col-md-6\">\n";
echo            "<h4 class=\"box-title\"><h4>\n";
echo            "<div id='subject'>";
echo ($subject);
echo            " <h6><p style=\"color:black\"> Created on  $formattedTime</p></h6>";
echo            "</h4>\n";
echo            "<p style=\"color:black\"><i class=\"fa fa-user\"></i>&nbsp;&nbsp;  $agent_name  &nbsp;&nbsp;&nbsp;&nbsp;<i class=\"fa fa-laptop\"></i>&nbsp;&nbsp;  $deviceID</p><p style=\"color:black\"><i class=\"fa fa-inbox\"></i>&nbsp;&nbsp;  $row_thread</p></div><div class=\"col-md-4\"><br>$message_assignment<br><div class=\"row\">$new_update_notice</div>\n";
echo            "</div></div></a>\n";
echo            "<div id=\"$id\" class=\"panel-collapse collapse\"><hr>\n";
echo            "<div class=\"box-body\">\n";
echo            "<div class=\"box-body\"><div class=\"col-lg-8\">\n";
// Update Ticket Form Start
echo            "<form role=\"ticket-update\" name=\"ticket-update\" enctype=\"multipart/form-data\" method=\"post\" action=\"submit_mail.php\"\">                    
                    <div class=\"form-group\">
                        <div class=\"input-group input-group-lg\">
                            <input type=\"description\" class=\"form-control input-lg\" placeholder=\"Whats the update?\" tabindex=1 name=\"title\" autocomplete=\"off\" required=\"true\"/></a>
                                <span class=\"input-group-btn progress-demo\">
                                <input type=\"hidden\" name=\"number\" value=\"$number\"/>
                                <input type=\"hidden\" name=\"username\" value=\"$username\"/>

                                    <button class=\"btn btn-info btn-flat ladda-button\" data-style=\"expand-right\" type=\"submit\" tabindex=\"5\" id=\"refresh\"><i class=\"glyphicon glyphicon-send\"></i></button>
                                </span>                 
                                </div>
                                </div>


                  <div id=\"$id\"></div>
                  </form>";



                echo               " <ul class=\"timeline\">

    <!-- timeline time label -->
    <li class=\"time-label\">
        <span class=\"bg-red\">
           $formattedTime_Date
        <!--   \\Date and Month format 
        </span>
    </li>";

 echo  " <!-- /.timeline-label -->

    <!-- timeline item -->
    <li>

        <!-- timeline icon -->
        <i class=\"fa fa-envelope bg-blue\"></i>
        <div class=\"timeline-item\" id=\"#$tid\">

            <span class=\"time\"><i class=\"fa fa-clock-o\"></i>

        $time_ago

</span>

            <h3 class=\"timeline-header\"><a href=\"#$tid\">$fullname</a></h3>";

    echo       "<div class=\"timeline-body\" id=\"#$tid\">";

echo "Updated by $fullname";
echo "<pre>";
echo print_r($res, TRUE);
echo "</pre>";
   echo        " <div class='timeline-footer'>
            </div>


    </li>
    <!-- END timeline item -->

</ul>   \n";

0 个答案:

没有答案