Undefined index error for the last element of array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • umarsulur
    New Member
    • Feb 2012
    • 1

    Undefined index error for the last element of array

    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()...ki ndly help pls.....


    Here is the code......
    Code:
    <?php
    
    include("includes/global_inc.php");
    
    $qry1=$_REQUEST['qry'];
    $feilds2=$_REQUEST['fields1'];
    $cnt=$_REQUEST['count'];
    $feild_name=explode(",",$feilds2);
    $iquery=mysql_query("$qry1")
    	or die(mysql_error());
    
    echo "<table border='1'>";
    echo "<tr>";
    for($i=0;$i<$cnt;$i++)
    {
    echo "<th>".$feild_name[$i]."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>";
    
    }
    
    echo "</tr>";
    
    for($g=0;$g<$cnt;$g++)
    {
    while($test=mysql_fetch_array($iquery))
    	{
    		echo "<tr align='center'>";
    		
    		
    		
    			echo"<td><font color='black'>".$test[$feild_name[$g]]."</font></td>";
    		
    		
    
    					
    		echo"</tr>";
    	}
    	
    }
    
    echo "</table>";
    ?>
  • YarrOfDoom
    Recognized Expert Top Contributor
    • Aug 2007
    • 1243

    #2
    Are you sure $cnt has the correct information? Why don't you calculate it yourself?

    Comment

    Working...