KubeR Posted July 27, 2013 Share Posted July 27, 2013 Hi, I am trying to make a code which will count the number of fields are in the column,fetch all of them,store in an array and place them in the menu options that were created by a loop allocated by the number of rows counted before. But for some reason it shows me null (nothing) or undefined offset and only one is being placed. Can somebody explain why is this happening ? here is the code I made for it : <?phperror_reporting(-1);include("config.php");global $text,$pages;$query = "SELECT title FROM home";if($result = mysqli_query($link,$query)) {$pages = mysqli_num_rows($result);$i = -1;while($row=mysqli_fetch_row($result)) {$i += 1;$text[$i] = $row[$i];}mysqli_free_result($result);}mysqli_close($link);?> Before the hand,thanks, Greetings, KubeR. Quote Link to comment https://forums.phpfreaks.com/topic/280559-undefined-offset-or-null-errors/ Share on other sites More sharing options...
Solution requinix Posted July 27, 2013 Solution Share Posted July 27, 2013 $i += 1; $text[$i] = $row[$i];There is only one column in the results. You shouldn't need $i at all, let alone be changing it over time. $text[] = $row[0];You should also initialize $text = array(); before the loop, since it's undefined when you're trying to append to it (as [] does). Quote Link to comment https://forums.phpfreaks.com/topic/280559-undefined-offset-or-null-errors/#findComment-1442372 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.