2013-07-27 54 views
0

首先,我是全新的PHP和MySQL。非重复数据

我的目标是显示数据库中学生的证词。它显示了两个证词,但我需要他们成为两个不同的证词。请帮助!

<div class="block_main_testimonials"> 
         <h4>Student Corner</h4> 
<?php 
// Connect to the file above here 
require "includes/connect.php"; 

    $data = mysql_query("SELECT * FROM `testimonials` ORDER BY RAND() LIMIT 0,2") 
    or die(mysql_error()); 

    $info = mysql_fetch_array($data) ; 

?> 
         <div class="one_half"> 
          <div class="block_testimonials_2"> 
           <div class="content"> 
            <div class="text"> 
             <p>“<?php echo $info['quote'] ;?>”</p> 

             <div class="tail"></div> 
            </div> 

            <div class="author"> 
             <p><?php echo $info['name'] ; ?>,<span class="position"> <a href="<?php echo $info['url'] ; ?>"> <?php echo $info['department']; ?></a></span></p></div> 
           </div> 
           <div class="clearboth"></div> 
          </div> 
         </div> 

         <div class="one_half last"> 
          <div class="block_testimonials_2"> 
           <div class="content"> 
            <div class="text"> 
             <p>“<?php echo $info['quote'] ;?>”</p> 

             <div class="tail"></div> 
            </div> 

            <div class="author"> 
             <p><?php echo $info['name'] ; ?>,<span class="position"> <a href="<?php echo $info['url'] ; ?>"> <?php echo $info['department']; ?></a></span></p></div> 
           </div> 
           <div class="clearboth"></div> 
+0

使用像这样的'SELECT DISTINCT * FROM testimonials ...' – 2013-07-27 00:44:07

+1

特别是没有工作?如果您直接对数据库执行该查询,结果是否可以?你是否收到任何错误消息,或者数据不是你所期望的? – rutter

回答

0

您只提取了结果集的第一行。

在显示您希望成为结果集的第二行之前再次调用此调用。为了获得最佳效果,请在循环中调用它,直到结果集耗尽。

$info = mysql_fetch_array($data) ; 

除此之外,你现在可能已经想通了,因为它太容易badguys到PWN使用它的网站mysql接口被认为是有害的。