Zookal
Zookal

We’d love to hear any feedback or comment from you!

© 2011-2021 Zookal Pty Ltd

View question and answer

From our collection of questions and answers
Engineering · Computer Science
Question details

I am attempting to use JSON and AJAX to make a dynamic web page which loads data from a php script which should be edited as little as possible

However when attempting to load the information, the script prints:

Fatal error: Call to undefined method mysqli_result::fetchObject() in /home/unn_w16011531/public_html/getOffers.php on line 30

Script file:

var htmlOfferDiv = document.getElementById("offers");
var btn = document.getElementById("getHTMLOffers");

btn.addEventListener("click", function() {
    var htmlOffer = new XMLHttpRequest();
    htmlOffer.open('GET', 'getOffers.php');
    htmlOffer.onload = function () {
        var offerData = htmlOffer.responseText;
        renderHTML(offerData);
    };
    htmlOffer.send();
});

    function renderHTML(data){
        var htmlOffers = "";

        for(i = 0; i < data.length; i++){
            htmlOffers += "

" + data[i] + "

"; } htmlOfferDiv.insertAdjacentHTML('beforeend', htmlOffers) }

The broken part of the getOffers.php file:

function getHTMLOffer($dbConn) {
   try {
       // store the sql for a random special offer, the sql wraps things using concat in an html 'wrapper'
       $sql = "select concat('

“',recordTitle,'”
\nCategory: ',catDesc,'
\nPrice: ',recordPrice,'

') as offer from nmc_special_offers inner join nmc_category on nmc_special_offers.catID = nmc_category.catID order by rand() limit 1"; // execute the query $rsOffer = $dbConn->query($sql); // get the one offer returned $offer = $rsOffer->fetchObject(); //This is line 30 // return the offer return $offer->offer; } catch (Exception $e) { return "Problem: " . $e->getMessage(); } }

How can i fix the issue of the undefined call so that the page will be able to use the file?

If any more information is needed, I will update the question.

Thanks in advance





Here is the database connection file.

<?php
//Reusable script to connect to the Database


$dbConn = new mysqli('localhost', 'username', 'password', 'unn_w16011531');

if ($dbConn->connect_error) {
    echo "<p>Connection Failed: " . $dbConn->connect_error . "</p>\n";
    exit;

}
?>
Answer
Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.

Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.