Jump to content
Sign in to follow this  
webdevdea

Json help

Recommended Posts

at my link http://dandewebwonders.com/BBProject%204/index.php

when you click on players you see the error..

this is what i need to do ..

change data type from html to json, fix the controller error, and change it to parse the data.data object.

 case "listPlayers_Data" :
        $response = null;
        $results = array();
        $players = new PlayersClass();
        foreach ($players -> RetrieveAll() as $row) {
            $results[] = new PlayerListModel($row -> Id);
        }
        $response -> data = $results;
        echo json_encode($response);
        break;

and a link to the project on github

https://github.com/deannariddlespur/bb_Project/blob/master/Controllers/Controller.php

Share this post


Link to post
Share on other sites


Warning: Creating default object from empty value in /home3/aundie/public_html/dandewebwonders.com/BBProject 4/Controllers/Controller.php on line 41

{"data":[{"Id":"1","FirstName":"Chico","LastName":"Escuela","HomeTown":"San Juan, PR","Bats":"L","Throws":"R","Team":null},{"Id":"2","FirstName":"Christopher","LastName":"Henry","HomeTown":"Pittsburgh, PA","Bats":"","Throws":"","Team":null},{"Id":"3","FirstName":"Travis","LastName":"Hubbard","HomeTown":"Boise, ID","Bats":"","Throws":"","Team":null},{"Id":"4","FirstName":"Richard","LastName":"McCoy","HomeTown":"Austin, TX","Bats":"","Throws":"","Team":null},{"Id":"5","FirstName":"Al","LastName":"Torres","HomeTown":"Baltimore, MD","Bats":"","Throws":"","Team":null},{"Id":"6","FirstName":"Everett","LastName":"Greer","HomeTown":"Wilmington, DE","Bats":"","Throws":"","Team":null},{"Id":"7","FirstName":"Johnnie","LastName":"Joseph","HomeTown":"St. Paul, MN","Bats":"","Throws":"","Team":null},{"Id":"8","FirstName":"Milton","LastName":"Osborne","HomeTown":"Davidson, TN","Bats":"","Throws":"","Team":null},{"Id":"9","FirstName":"Dewey","LastName":"McDonald","HomeTown":"St. Louis, MO","Bats":"","Throws":"","Team":null},{"Id":"10","FirstName":"Ervin","LastName":"Lawrence","HomeTown":"Anaheim, CA","Bats":"","Throws":"","Team":null},{"Id":"11","FirstName":"Thomas","LastName":"Copeland","HomeTown":"St. Petersburg, FL","Bats":"","Throws":"","Team":null},{"Id":"12","FirstName":"Christian","LastName":"Shelton","HomeTown":"Akron, OH","Bats":"","Throws":"","Team":null},{"Id":"13","FirstName":"Jackie","LastName":"Harris","HomeTown":"Rochester, NY","Bats":"","Throws":"","Team":null},{"Id":"14","FirstName":"Bob","LastName":"Barnes","HomeTown":"Newark, NJ","Bats":"","Throws":"","Team":null},{"Id":"15","FirstName":"Woodrow","LastName":"Zimmerman","HomeTown":"Baltimore, MD","Bats":"","Throws":"","Team":null},{"Id":"16","FirstName":"Willard","LastName":"Harrington","HomeTown":"Glendale, AZ","Bats":"","Throws":"","Team":null},{"Id":"17","FirstName":"Orville","LastName":"Gregory","HomeTown":"Reno, NV","Bats":"","Throws":"","Team":null},{"Id":"18","FirstName":"Tony","LastName":"Jennings","HomeTown":"Denver, CO","Bats":"","Throws":"","Team":null},{"Id":"19","FirstName":"Benjamin","LastName":"Hawkins","HomeTown":"Philadelphia, PA","Bats":"","Throws":"","Team":null},{"Id":"20","FirstName":"Andre","LastName":"Wells","HomeTown":"Kansas City, MO","Bats":"","Throws":"","Team":null},{"Id":"21","FirstName":"Rafael","LastName":"McDaniel","HomeTown":"Norfolk, VA","Bats":"","Throws":"","Team":null}]}
  • Like 1

Share this post


Link to post
Share on other sites
<br />
<b>Warning</b>:  Creating default object from empty value in <b>/home3/aundie/public_html/dandewebwonders.com/BBProject 4/Controllers/Controller.php</b> on line <b>41</b><br />
{"data":[{"Id":"1","FirstName":"Chico","LastName":"Escuela","HomeTown":"San Juan, PR","Bats":"L","Throws":"R","Team":null},{"Id":"2","FirstName":"Christopher","LastName":"Henry","HomeTown":"Pittsburgh, PA","Bats":"","Throws":"","Team":null},{"Id":"3","FirstName":"Travis","LastName":"Hubbard","HomeTown":"Boise, ID","Bats":"","Throws":"","Team":null},{"Id":"4","FirstName":"Richard","LastName":"McCoy","HomeTown":"Austin, TX","Bats":"","Throws":"","Team":null},{"Id":"5","FirstName":"Al","LastName":"Torres","HomeTown":"Baltimore, MD","Bats":"","Throws":"","Team":null},{"Id":"6","FirstName":"Everett","LastName":"Greer","HomeTown":"Wilmington, DE","Bats":"","Throws":"","Team":null},{"Id":"7","FirstName":"Johnnie","LastName":"Joseph","HomeTown":"St. Paul, MN","Bats":"","Throws":"","Team":null},{"Id":"8","FirstName":"Milton","LastName":"Osborne","HomeTown":"Davidson, TN","Bats":"","Throws":"","Team":null},{"Id":"9","FirstName":"Dewey","LastName":"McDonald","HomeTown":"St. Louis, MO","Bats":"","Throws":"","Team":null},{"Id":"10","FirstName":"Ervin","LastName":"Lawrence","HomeTown":"Anaheim, CA","Bats":"","Throws":"","Team":null},{"Id":"11","FirstName":"Thomas","LastName":"Copeland","HomeTown":"St. Petersburg, FL","Bats":"","Throws":"","Team":null},{"Id":"12","FirstName":"Christian","LastName":"Shelton","HomeTown":"Akron, OH","Bats":"","Throws":"","Team":null},{"Id":"13","FirstName":"Jackie","LastName":"Harris","HomeTown":"Rochester, NY","Bats":"","Throws":"","Team":null},{"Id":"14","FirstName":"Bob","LastName":"Barnes","HomeTown":"Newark, NJ","Bats":"","Throws":"","Team":null},{"Id":"15","FirstName":"Woodrow","LastName":"Zimmerman","HomeTown":"Baltimore, MD","Bats":"","Throws":"","Team":null},{"Id":"16","FirstName":"Willard","LastName":"Harrington","HomeTown":"Glendale, AZ","Bats":"","Throws":"","Team":null},{"Id":"17","FirstName":"Orville","LastName":"Gregory","HomeTown":"Reno, NV","Bats":"","Throws":"","Team":null},{"Id":"18","FirstName":"Tony","LastName":"Jennings","HomeTown":"Denver, CO","Bats":"","Throws":"","Team":null},{"Id":"19","FirstName":"Benjamin","LastName":"Hawkins","HomeTown":"Philadelphia, PA","Bats":"","Throws":"","Team":null},{"Id":"20","FirstName":"Andre","LastName":"Wells","HomeTown":"Kansas City, MO","Bats":"","Throws":"","Team":null},{"Id":"21","FirstName":"Rafael","LastName":"McDaniel","HomeTown":"Norfolk, VA","Bats":"","Throws":"","Team":null}]}

how would i change data type from html to json,

Share this post


Link to post
Share on other sites

Forget that for a moment and focus on the error message. And on fixing whatever caused it.

  • Like 1

Share this post


Link to post
Share on other sites

You assign null to $response in line 35, but then you try to assign an array to $response->data in line 41 as if null was an object. This is of course nonsensical. Either make $response an array and use the $response['data'] syntax, or make it an actual object.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

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.