非重复数据

尼克·琼斯

首先,我是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>
琼斯

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

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

    $info = mysql_fetch_array( $data ) ; 

除此以外,您可能现在已经知道,该mysql界面被认为是有害的,因为对于那些顽固的家伙来说,使用界面太容易了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章