dongwen3410 2013-06-29 19:33
浏览 60

避免在PHP SQL中重复循环

I have a problem with my code that the result has some duplicate loop.

Here is my code:

 <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" data-iceapw="6">
 <?php for($a=0;$a<5;$a++) {
$sql = "SELECT * FROM personality_question_tbl where personality_question_id in (select personality_question_id from
                                                                        personality_question_type_tbl where
                                                                        personality_id='P01' ) ORDER BY RAND() limit 1" ;
$result = mysql_query($sql); 
while ($row = mysql_fetch_array($result)) {
    extract ($row);
    }
?> 


<table width="200" border="0">
  <tr>
    <td><?php echo $personality_question_id[$a]; ?> </td>
  </tr>
  <tr>
    <td>
      <table width="200">
        <tr>
          <td><label>
            <input type="radio" name="answer" value="1" id="answer_0">
            yes</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="radio" name="answer" value="0" id="answer_1">
            no</label></td>
        </tr>
      </table>
    </td>
  </tr>
 </table>
 </form>
<?php } ?>
<input name="submit" type="submit" value="Go">
<input name="submitted" type="hidden" value="TRUE">
</form>

The problem is I still get the duplicate result in PHP although there are no duplicate data in database...

  • 写回答

1条回答 默认 最新

  • dongshetao1814 2013-06-29 20:03
    关注

    Your doing a for loop, of course your going to have duplication.. unless I am not understanding your question

    remove <?php for($a=0;$a<5;$a++) { and you will solve your duplication

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度