Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    pg_fetch_object and while prints "Resource id#3"... ??

    PHP Code:

    hmProdQuery
    pg_query($dbcon"SELECT id, name, author, price, publisher, image, description FROM eza_products");
            while (
    $product pg_fetch_object($hmProdQuery)) //loop through each row, store each column/value that is selected into an object called 
            
    {
                echo 
    "<img id='bookimg' width='92' height='119' src='images/bookimages/$product->image'>\n"//show the image field for the current row.
                
    echo "<img id='tag' src=images/tag.gif>\n";
                echo 
    "<p id=dispPrice class=dispPrice>$product->price</p>\n"//object notation, similar to $row[0] or $row['name']
                
    echo "<p id=bookTitle class=bookTitle>$product->name</p>\n";
                echo 
    "<p id=author class=author>$product->author $product->publisher</p>\n";
                echo 
    "<p id=description class=description>$product->description</p>\n";
                if (
    $_SESSION['logged'] == true) { //if the user is logged in...offer them to add this product into their session
                    
    echo "<button type='button'><a href='cart.php?action=add&id=$product->id'>Add to Cart</button>\n";
                } else { 
    //otherwise, provide a link to login.
                    
    echo "<button type='button'><a href='login.php'>Login</a></button>\n\n";
                }
            } 
    Results in:
    Code:
            
    
    Resource id #3<img id='bookimg' width='92' height='119' src='images/bookimages/image01.jpg'> 
    <img id='tag' src=images/tag.gif> 
    <p id=dispPrice class=dispPrice>19.99</p> 
    <p id=bookTitle class=bookTitle>PHP and MySQL</p> 
    <p id=author class=author>Luke Welling Pearson Education</p> 
    <p id=description class=description>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan bibendum odio, ut pretium leo cursus quis. Nullam eget magna lobortis libero consequat lacinia ut in tellus. </p> 
    <button type='button'><a href='login.php'>Login</a></button>
    Why does Resource id#3 show up and how do i get rid of it...?

    EDIT:

    oops... I had

    PHP Code:

    echo $dbcon
    silly me. Fixed. Thanks
    Last edited by nockemout; 05-23-2011 at 10:01 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •