Jump to content

Undefined offset or null errors


Recommended Posts


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,
Link to comment
Share on other sites

$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).
Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.