423,311 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,311 IT Pros & Developers. It's quick & easy.

mysql_fetch_array not display first row

P: 1
Here i want to display all the columns but i have getting all the columns except first one. How i can get first one ? Anyone can help me to solve this problem.
Expand|Select|Wrap|Line Numbers
  1. <form method='get'>
  2.  
  3.    <?php
  4.  
  5. if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
  6.   //we give the value of the starting row to 0 because nothing was found in URL
  7.   $startrow = 0;
  8. //otherwise we take the value from the URL
  9. } else {
  10.   $startrow = (int)$_GET['startrow'];
  11. }
  12.  
  13. $result = mysql_query("select s.s_id,s.s_name, DATE_FORMAT(s.s_date,'%d/%m/%Y'),DATE_FORMAT(s.s_emaildate,'%d/%m/%Y'),s.s_category,s.p_jawab,a.sc_category,b.staff_username from soal_jawab s, category a, staff b 
  14. where s.s_category = a.sc_id 
  15. and s.p_jawab = b.ic_num 
  16. and s.s_category = 'SC1'
  17. LIMIT $startrow, 10;")or
  18. die(mysql_error());
  19. $num=mysql_fetch_array($result);
  20.  
  21. if($num>0)
  22.     {    
  23.     ?>               
  24. <table id="rounded-corner">
  25.     <thead>
  26.         <tr>
  27.             <th>NO.SIRI</th>
  28.             <th>TARIKH TERIMA EMAIL</th>
  29.             <th>KATEGORI</th>
  30.             <th>PANEL PENJAWAB</th>
  31.             <th>TARIKH SERAH SOALAN</th>
  32.             <th>TARIKH BALAS EMAIL</th>
  33.             <th>KEMASKINI</th>
  34.             <th>PADAM</th>
  35.         </tr>
  36.     </thead>
  37.         <tfoot>
  38.         <tr>
  39.             <td colspan="12"></td>
  40.         </tr>
  41.     </tfoot>
  42.  
  43. <?php
  44. for($i=-1;$i<$num;$i++)
  45. {
  46. $num = mysql_fetch_array($result);
  47. ?>
  48.  
  49.     <tbody>
  50.         <tr class="odd" onclick="window.document.location='butiransoalan.php?s_id=<?php echo $num[0];?>';">
  51.  
  52.             <td><?php echo $num['s_id'];?></td>
  53.             <td><?php echo $num[3];?></td>
  54.             <td><?php echo $num['sc_category'];?></td>
  55.             <td><?php echo $num['staff_username'];?></td>
  56.             <td><?php echo $num[2];?></td>
  57.             <td></td>
  58.             <td><a href="#"><img src="images/edit.png" alt="" title="" border="0" /></a></td>
  59.             <td><a href="#"><img src="images/trash.gif" alt="" title="" border="0" /></a></td>
  60.  
  61.         </tr>
  62.  
  63.  
  64.     </tbody>
  65.     <?php } ?>
  66. </table>
  67. <?php } ?>
  68.  
  69. <?php
  70.  
  71. echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a>';
  72.  
  73. $prev = $startrow - 10;
  74.  
  75. //only print a "Previous" link if a "Next" was clicked
  76. if ($prev >= 0)
  77.     echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'">Previous</a>';
  78. ?>
  79. </form>
  80.  
Oct 19 '15 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
you fetch the first result set on line #19 for the table head, but do not use its data. hence you’re missing the first result set in the table body.
Oct 20 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.