2014-09-29 180 views
0

我需要基於php的website解決方案。我在主頁上有一個證書,其中內容應該從後端動態顯示。並且我還需要一個條件語句。如果證書從後臺獲得批准,則在主頁上顯示內容,如果沒有,則不顯示。使用條件語句顯示動態內容

Images

的Html炫魅代碼

 <aside id="home-marketing-testimonials"> 
      <span class="section_title"><h6 style="color:#fff200; font-weight:bold;">Our Students Say it Best</h6></span> 
      <div class="testimonials" style="text-align:justify;"> 
       <div class="testimonial"> 
       <blockquote style="color:#fff;"> 
        <?php 
      $nsql = mysql_query("select * from testimonials order by id desc limit 0,1"); 
      while($nrow = mysql_fetch_array($nsql)) 
      { 
       ?> 

       <?php echo $nrow[5]; ?></a></strong> 
        <?php 
        $nrowlen = strlen($nrow[1]); 
        if($nrowlen > 220) 
        { 
         echo substr($nrow[1],0,220)."..."; 
        } 
        else 
        { 
         echo "<div style='font-size:12px;color:yellow; margin-top:10px;'>".$nrow[1]."</div>"; 
        } 
        ?> 
       </blockquote> 
        <?php 
      } 
      ?> 
       <strong class="client_identity" style="color:#fff; float:left;"><a class="test_author" href="students-testimonials.php"></a></strong> 
       </div> 


      </div> 

     </aside> 

後端個人鑑定代碼:

<div class="content_display"> 
     <div class="widgetcontent bordered"> 
       <div class="row-fluid"> 
       <!--<div align="right"><a href="add_pages.php" style="margin-bottom: 10px; color:#fff;" class="btn btn-primary">Add New</a></div>--> 
     <table class="table table-bordered" width="100%"> 
       <colgroup> 
        <col class="con0" /> 
        <col class="con1" /> 
        <col class="con0" /> 
        <col class="con1" /> 
        <col class="con0" /> 
        <col class="con1" /> 
       </colgroup> 
       <thead> 

        <tr> 
         <th width="10%">S.No</th> 
         <th width="20%">Name</th> 
         <th width="20%">Student ID</th> 
         <th width="20%">Email</th> 
         <th width="10%">Status</th> 
         <th width="20%">Options</th> 
        </tr> 
       </thead> 
       <tbody> 
       <?php 
       $i=1; 
       $sql=mysql_query("select * from testimonials order by id desc"); 

       while($res=mysql_fetch_array($sql)) 
       { 
       ?> 
        <tr> 
         <td ><?php echo $i; ?></td> 
         <td><?php echo $res['name']; ?></td> 
         <td><?php echo $res['stuid']; ?></td> 
         <td><?php echo $res['email']; ?></td> 
         <td><?php 
         if($res['cstatus']=="0") 
         { 
          echo "Disapproved"; 
         } 
         else 
         { 
          echo "Approved"; 
         } 
         ?> 
         </td> 
         <td> 
         <a href="view_testimonial.php?id=<?php echo $res['id']; ?>">View</a>&nbsp;&nbsp; 
         <?php 
         if($res['cstatus']=="0") 
         { 
          echo '<a href="approve.php?id='.$res['id'].'">Approve</a>'; 
         } 
         else 
         { 
          echo '<a href="disapprove.php?id='.$res['id'].'">Disapprove</a>'; 
         } 
         ?> 
         &nbsp;&nbsp;<a href="#" onClick="ConfirmChoice(<?php echo $res['id']; ?>);">Delete</a></td> 
        </tr> 
        <?php 
       $i++; }?></tbody></table></div></div></div> 

回答

1

這與MySQL線前端代碼改變時,循環從正確的位置開始,並糾正if/else語句...

<aside id="home-marketing-testimonials"> 
     <span class="section_title"><h6 style="color:#fff200; font-weight:bold;">Our Students Say it Best</h6></span> 
     <div class="testimonials" style="text-align:justify;"> 
     <?php 
      $nsql = mysql_query("select * from testimonials where cstatus=1 order by id desc limit 3"); 
      while($nrow = mysql_fetch_assoc($nsql)) { 
       //start testimonial div and blockquote 
       echo "<div class='testimonial'><blockquote style='color:#fff;'>"; 

       //shorten quote if too long 
       $nrowlen = strlen($nrow['comments']); 
       if ($nrowlen > 220) $nrow['comments']=substr($nrow['comments'],0,220)."..."; 

       //insert quote and end blockquote 
       echo "<div style='font-size:12px;color:yellow; margin-top:10px;'>".$nrow['comments']."</div></blockquote>"; 

       //student identity (start and end) 
       echo "<strong class='client_identity' style='color:#fff; float:left;'><a class='test_author' href='students-testimonials.php'>".$nrow['name']."</a></strong>"; 

       //end testimonial div 
       echo "</div>"; 
      } 
     ?>    
     </div> 
</aside> 

我也用mysql_fetch_assoc,而不是mysql_fetch_array這樣我就可以使用的列名($ nrow [ '名']),而不是列的ID號($ nrow [1])

還要注意我在這裏使用LIMIT 3。它看起來像在你的網站上,你只需要拉三個引號。如果這可能是一個不同的數字,只需更改數字3.

+0

你有沒有看到我的網頁,如果我有三個推薦,它會改變,還是我應該在HTML頁面進行總和更改,如果有。請建議 – Zain 2014-09-29 11:50:18

+0

現在你的最後有限制0,1,這意味着它只會顯示一個。你可以擺脫限制0,1部分,它會得到很多存在的匹配cstatus = 1 – rgbflawed 2014-09-29 11:53:37

+0

我需要證明改變..但現在第1 testimoials只顯示 – Zain 2014-09-29 11:53:53