2014-09-29 186 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