Jump to content

Undefined offset or null errors


KubeR
Go to solution Solved by requinix,

Recommended Posts

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

  • Solution

$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 thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.