Foreach在foreach里面

时间:2014-03-05 18:59:31

标签: php mysql foreach

我正在尝试制作用户个人资料页面系统,但当我在while内部foreachwhileforeach时,它不会执行内部和循环之后的任何代码。

foreach($db->query("SELECT * FROM `members` WHERE username = '$user'") as $row) {

    echo "
         <div class='page-header'>
            <div class='row'>
               <div class='span12'>
                  <div class='tabbable'>
                     <ul class='nav nav-tabs'>
                        <li class='active'>
                           <a data-toggle='tab' href='#about'>About $user</a>
                        </li>
                        <li>
                           <a data-toggle='tab' href='#infractions'>Infractions</a>
                        </li>
                     </ul>
                     <div class='tab-content' style='overflow: visible;'>
                        <div class='tab-pane active' id='about'>
                           <div class='row'>
                              <div class='span9'>
                                 <div class='span4' style='float:left; width:25%'>
                                   ".$row['reputation']."
                                 </div>
                              </div>
                           </div>
                        <div class='tab-pane' id='infractions'>
                           <div class='row'>
                              <div class='span12'>
                              <br>
                              <h3>Received Infractions</h3>
                                 <table class='table table-bordered table-striped'>
                                    <thead>
                                       <tr>
                                          <th width='13%'>Issuer</th>
                                          <th width='13%'>Punished</th>
                                          <th width='34%'>Reason</th>
                                          <th width='7%'>Type</th>
                                          <th width='7%'>Status</th>
                                          <th width='9%'>Expires</th>
                                          <th width='12%'>Date</th>
                                       </tr>
                                    </thead>
                                    <tbody>
                                       <tr class=''>";
                                       //foreach($db->query("SELECT * FROM `infractions` WHERE reciver = '$user'") as $infraction) {
                                        $stmt = $db->query("SELECT * FROM `infractions` WHERE reciver = '$user'");
                                        while($infraction = $stmt->fetch(PDO::FETCH_ASSOC)) {
                                          echo "<td><a href='/profiles/".$infraction['issuer']."' style='color: #F55'>".$infraction['issuer']."</a></td>
                                        <td><a href='/profiles/".$infraction['reciver']."'>".$infraction['reciver']."</a></td>
                                        <td>".$infraction['reason']."</td>
                                        <td style='color:";
                                        if($infraction['type']=="ban"){echo "red";}
                                        elseif($infraction['type']=="tempban"){echo "orange";}
                                        elseif($infraction['type']=="kick"){echo "yellow";}
                                        elseif($infraction['type']=="mute"){echo "blue";}
                                        echo "'>";
                                        if($infraction['type']=="ban"){echo "Ban";}
                                        elseif($infraction['type']=="tempban"){echo "Tempban";}
                                        elseif($infraction['type']=="kick"){echo "Kick";}
                                        elseif($infraction['type']=="mute"){echo "Mute";}
                                        echo "</td><td><span style='color:";
                                        if($infraction['appstatus']=="0"){echo "N/A";}
                                        elseif($infraction['appstatus']=="1"){echo "black";}
                                        elseif($infraction['appstatus']=="2"){echo "blue";}
                                        elseif($infraction['appstatus']=="3"){echo "red";}
                                        elseif($infraction['appstatus']=="4"){echo "green";}
                                        echo "orange";
                                        echo "'>";
                                        if($infraction['appstatus']=="0"){echo "N/A";}
                                        elseif($infraction['appstatus']=="1"){echo "Not Appealed";}
                                        elseif($infraction['appstatus']=="2"){echo "Appeal Pending";}
                                        elseif($infraction['appstatus']=="3"){echo "Appeal Rejected";}
                                        elseif($infraction['appstatus']=="4"){echo "Appeal Accepted";}
                                        echo"</span>
                                        </td>
                                        <td>
                                        Never
                                        </td>
                                        <td data-container='body' data-placement='left' rel='tooltip' title='' data-original-title='January 4th, 2014 -  6:20 PM'>
                                        <a href='/infractions/52c8a54fc8f2382195d7b3c4'>
                                        17 minutes
                                        ago
                                        </a>";
                                         }
                                          echo "</td>
                                       </tr>
                                    </tbody>
                                 </table>
         </section>
      </section>";

(忽略unmatched {}错误,因为我没有花费大量时间来缩短它,我也可以连接到数据库,我只是没有包含它。)

我没有得到任何错误,并且在第二个foreach之前的所有事情都可以正常工作。

0 个答案:

没有答案