mysqli两次调用相同的数据 [英] mysqli calling same data twice

查看:67
本文介绍了mysqli两次调用相同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释一个详细的答案,因为无法在stackoverflow上找到它

Can anyone explain a detailed answer as, am not able to found it on stackoverflow

<?php
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
  ini_set('log_errors',1);
  mysqli_report(MYSQLI_REPORT_ALL);
   $link = mysqli_connect('localhost', 'root', '', 'test') or 
  die(mysqli_connect_error());
    $query2 = "Select * from qualifications";
    $result=mysqli_query($link,$query2)or die (mysqli_error($link));   
    ?>
 <form>
  <table>
     <tr>
        <td>
           <select name="short_term_degree" id="short_term_degree" >
              <option value="">Select</option>
              <?php
                 while ( $d=mysqli_fetch_assoc($result)) {
                  echo "<option 
  value='".$d['qual_id']."'>".$d['qualification']."</option>";
                  }
                  ?>
           </select>
        </td>
     </tr>
     <tr>
        <td>
           <select name="short_term_course" id="short_term_course" >
              <option value="">Select</option>
              <?php
                 while ( $d=mysqli_fetch_assoc($result)) {
                 echo "<option 
  value='".$d['qual_id']."'>".$d['qualification']."</option>";
                 }
                 ?>
           </select>
        </td>
       </tr>
    </table>
  </form>
</body>

我得到的结果

<select name="short_term_degree" id="short_term_course">
 <option value="">Select</option>
 <option value="268">Graduate</option>
 <option value="269">Mtech</option>
 <option value="353">Bachelor of Econimics</option>
</select>
<select name="short_term_course" id="short_term_course">
 <option value="">Select</option>
</select>

第二选择框不显示任何数据.这是什么原因.

The Second Select Box Doesn't show any data What's the reason.

为什么我需要在while之前再次使用mysqli_query()或mysqli_data_seek($ result,0); 在选择框中获取结果

why do i require to use again mysqli_query() before while OR mysqli_data_seek($result,0); for getting result in select box

推荐答案

返回与获取的行相对应的数组,并将内部数据指针向前移动.

Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.

当您尝试使用第二个while循环时,内部数据点仍在末尾.您没有做任何重置操作.

The internal data point is still at the end when you try to use your second while loop. You have done nothing to reset it.

您可以使用mysqli_data_seek($result, 0);

更新:

第一次while循环运行时,内部数据指针将向前移动并到达最后一个数据指针.因此,当您尝试使用第二个while循环从中获取数据时.因此没有更多数据,因为.已经到达了最后一个数据指针.

when first while loop run the internal data pointer move ahead and reach the last data pointer . so while your trying to get data from that using second while loop . so there is no more data because .it's already reach last data pointer .

这篇关于mysqli两次调用相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆