0

Hi Guys.

Ive got a small problem where I'm trying to display rows from my DB

Here is the code that I'm currently using:

<?php
$results = $sqli  = ("SELECT * FROM `books` ORDER BY `ISBN` ASC");

if ($results) { 

    //fetch results set as object and output HTML
    while($obj = $results->fetch_object())
    {
        echo '<div class="book">'; 
        echo '<form method="post" action="cart_update.php">';
        echo '<div class="book-thumb"><img src="images/'.$obj->BookImage.'"></div>';
        echo '<div class="book-content"><h3>'.$obj->Title.'</h3>';
        echo '<div class="book-desc">'.$obj->BookDesc.'</div>';
        echo '<div class="book-info">';
        echo 'Price '.$currency.$obj->Price.' | ';
        echo 'Qty <input type="text" name="product_qty" value="1" size="3" />';
        echo '<button class="add_to_cart">Add To Cart</button>';
        echo '</div></div>';
        echo '<input type="hidden" name="ISBN" value="'.$obj->ISBN.'" />';
        echo '<input type="hidden" name="type" value="add" />';
        echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
        echo '</form>';
        echo '</div>';
    }

}
?>

I keep getting the following error :
( ! ) Fatal error: Call to a member function fetch_object() on a non-object in C:\wamp\www\books.php on line 26

Line 26 is: while($obj = $results->fetch_object())

Any idea on what ive done wrong?

Thanks!

3
Contributors
2
Replies
15
Views
2 Years
Discussion Span
Last Post by linus72982
0

What's this supposed to be doing?

$results = $sqli  = ("SELECT * FROM `books` ORDER BY `ISBN` ASC");

Looks like it's just storing a string.

1

You're not actually making a call to the database. If I remember correctly, for mysqli it's something like $connectionVar->query("query string") or something similar. Currently, you're just storing a string in the mysqli var and the results var but no action is occuring.

EDIT for clarity:
If my mysqli knowledge is ripe enough, you first need to make sure you have connected to the db with something like $connection = mysqli_connect(connection arguments) where the arguments are things like your username, password, db name, host path, etc. Then do a $results = $connection->query("SELECT * FROM blah blah"), then iterate over $results to get your information.

Edited by linus72982: clarity

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.