PHP error: Notice: Undefined offset

Ranjank

i have created an api to fetch data from database to echo it as json and finally display it in html but while echoing the data,

i am getting below php errors

Notice: Undefined offset: 80 in /opt/lampp/htdocs/ReadExchange/api.php on line 16

Notice: Undefined offset: 79 in /opt/lampp/htdocs/ReadExchange/api.php on line 16

Notice: Undefined offset: 78 in /opt/lampp/htdocs/ReadExchange/api.php on line 16

and so on,

PHP Code

$db_result_set = $db->prepare('SELECT p.Id, p.FirstName, p.MiddleName, p.LastName, p.Gender, p.Location, p.Email, p.Mobile,b.BookTitle, b.BookGenre, b.BookWriter, b.BookDescription FROM personaldetails AS p LEFT JOIN bookdetails AS b ON b.UserId = p.Id ORDER BY p.Id DESC');;

$db_result_set->execute();

$final = [];
foreach ($db_result_set as $u) {

    if (!is_array($final[$u["Id"]])) {   //line 16 
        $final[$u["Id"]]= [
            "Id" => $u["Id"],
            "FirstName" => $u["FirstName"],
            "MiddleName" => $u["MiddleName"],
            "LastName" => $u["LastName"],
            "Gender" => $u["Gender"],
            "Location" => $u["Location"],
            "Email" => $u["Email"],
            "Mobile" => $u["Mobile"],
         ];
    }
    $final[$u["Id"]]["books"][] = [
        "BookTitle" => $u["BookTitle"],
        "BookGenre" => $u["BookGenre"],
        "BookWriter" => $u["BookWriter"],
        "BookDescription" => $u["BookDescription"],
    ];

}   
    
    header('Content-type: application/javascript');
    echo json_encode($final);
    

?>

i am not confirm but i think because of this i am not getting json data in html.

nospor

Not: if (!is_array($final[$u["Id"]]))

but: if (!isset($final[$u["Id"]]))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

"Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP

Why PHP doesn't throw "undefined offset" notice anymore?

PHP: error: Notice: unserialize(): Error at offset 438 of 750 bytes in

PHP Notice: Undefined offset: 39 in /my/path/*.phpFile on line 23

Array Undefined offset Notice in if condition [php]

Notice: Undefined offset: different rows

PHP- Notice: Undefined offset: 1

Notice: Undefined offset: 0...25

PHP Notice: Undefined offset: 1 while getting all directories

Notice: Undefined offset: 3 php sql

PHP MySql - Notice: Undefined variable Error

PHP Notice: Undefined index and Form Fields error

Notice: Undefined offset: 1 in

Yii 1.14 notice Undefined offset: 0 in CUrlManager.php

Notice: Undefined offset: 27 Why these error generated in PHP?

Notice: Undefined offset: 4 with loop through array in php

Notice: Undefined offset

PHP Notice: Undefined offset

Notice: Undefined offset: 9

Undefined offset 0 error in php

PHP error undefined variable notice how to fix?

Undefined offset notice messages

PHP list() error: "Undefined offset"

PHP Notice: Undefined offset: 1 - Transpose Array Columns to rows

php Getting sum arrays, but have "Notice" Undefined offset: 0

PhpSpreadsheet Notice: Undefined offset: 4

Notice: Undefined offset: 0 in and Undefined offset: 1 in php

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP

Error "Notice: Undefined offset: 1" when I activate plugin

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive