ashy Posted November 10, 2009 Share Posted November 10, 2009 Hi All, I kept getting undefined offset PHP notice for a simple for loop. For eg $va = array(); $i=0; while($row = mysql_fetch_array($result)) { $va[$i] = $row['id']; $i++; } It gives undefined offset at this line $++ thanks ashwin Link to comment https://forums.phpfreaks.com/topic/180962-undefined-offset-help/ Share on other sites More sharing options...
cags Posted November 10, 2009 Share Posted November 10, 2009 a.) that's not a for loop thats a while loop. b.) you don't have $++ in your code you have $i++ (but thats probably just a typo) c.) since $va is an array, you don't really need the $i variable at all. $va = array(); while($row = mysql_fetch_array($result)) { $va[] = $row['id']; } d.) you are getting undefined offset because you are attempting to access an item in the array that doesn't exist. Link to comment https://forums.phpfreaks.com/topic/180962-undefined-offset-help/#findComment-954768 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.