By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 915 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Undefined index error for the last element of array

P: 1
Undefined index for the last element of array while fetching datas from db through an array variable. I use for each loop to seperate and also in_array()...kindly help pls.....


Here is the code......
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. include("includes/global_inc.php");
  5.  
  6. $qry1=$_REQUEST['qry'];
  7. $feilds2=$_REQUEST['fields1'];
  8. $cnt=$_REQUEST['count'];
  9. $feild_name=explode(",",$feilds2);
  10. $iquery=mysql_query("$qry1")
  11.     or die(mysql_error());
  12.  
  13. echo "<table border='1'>";
  14. echo "<tr>";
  15. for($i=0;$i<$cnt;$i++)
  16. {
  17. echo "<th>".$feild_name[$i]."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>";
  18.  
  19. }
  20.  
  21. echo "</tr>";
  22.  
  23. for($g=0;$g<$cnt;$g++)
  24. {
  25. while($test=mysql_fetch_array($iquery))
  26.     {
  27.         echo "<tr align='center'>";
  28.  
  29.  
  30.  
  31.             echo"<td><font color='black'>".$test[$feild_name[$g]]."</font></td>";
  32.  
  33.  
  34.  
  35.  
  36.         echo"</tr>";
  37.     }
  38.  
  39. }
  40.  
  41. echo "</table>";
  42. ?>
  43.  
  44.  
  45.  
  46.  
Feb 16 '12 #1
Share this Question
Share on Google+
1 Reply


YarrOfDoom
Expert 100+
P: 1,247
Are you sure $cnt has the correct information? Why don't you calculate it yourself?
Feb 16 '12 #2

Post your reply

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