douyong6589 2017-01-09 14:01
浏览 6

显示未重复与数据库链接的行

I am new in php. I make a quiz app and I want to show questions that is not repeated again . here's my code. Please help me to show require result.

<?php
include('connect.php');
$sql = "SELECT * FROM quiz_question WHERE theme_id= 2 ORDER BY RAND ()";
$result = $conn->query($sql);
  if ($result->num_rows > 0) {
   // output data of each row
   while($row = $result->fetch_assoc()) {
     $id =  $row['id'];

       echo "
       <h2>" . $row["question"]. "</h2>";
       break;

     }
   }
   $check_id = array ($row['id']);
   echo $check_id['0'];
     if(array ($row['id']) == $check_id){
       echo "no question ";
     }
     else{
       echo "
       <h2>" . $row["question"]. "</h2>";
     }
?>
  • 写回答

1条回答 默认 最新

  • dongou1970 2017-01-09 14:43
    关注

    Your question is not clear. But I guess, you can solve it by array_unique($array).

    array_unique($array);

    <?php
      include('connect.php');
      $sql = "SELECT * FROM quiz_question WHERE theme_id= 2 ORDER BY RAND ()";
      $result = $conn->query($sql);
      if ($result->num_rows > 0) {
        // output data of each row
         while($row = $result->fetch_assoc()) {
         $id =  $row['id'];
         $question = $row['question'];
    
         echo "
          <h2>" . $row["question"]. "</h2>";
    
         $check_id = array($id);
        }
      }
    
      $check_id_unique=array_unique($check_id);
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序