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 9 of 9
  1. #1
    New Coder
    Join Date
    May 2011
    Location
    UK
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Database contents not showing

    PHP Code:
    <?php 
                    
    include '/database/config.php';
                    include 
    '/database/open.php';
                    
                    
    $query "SELECT * FROM slideshow";
                    
    $res mysql_query($query) or die('Query Error: '.$query .'<br /><br />'mysql_error());
                    
                    while(
    $row mysql_fetch_array($resMYSQL_ASSOC) or die('Result Error: '.$res.' 'mysql_error()));
                    {
                    echo    
    "<div class='slide'>
                            <h2>{$row['Brand']}</h2>
                            <p><a href='#'><img src='{$row['img']}' alt='An image that shows a {$row['Brand']} style shoe' width='215px' height='145px' border='0' /></a>
                                {$row['Details']}</p>
                            </div>
                            "
    ;
                    }
                    
                    include 
    '/database/close.php';
                
    ?>
    I get Result Error: Resource id #6

    where am i going wrong, my database has something inside the table, it connects fine, so whats going on

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I see column names like this:

    img
    Brand
    Details


    Brand and Details are capitalized, "img" is not.
    Did you type all of them correctly?
    Is that what they are officially named in your database?


    .

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,338
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    This:
    die('Result Error: '.$res.' '. mysql_error()));

    Your query for some reason, isn't correct so that part is trying to run.

    $res is a mysql resource so PHP can't print it but will instead tell you its a resource.

    Run your query through the SQL page in phpmyadmin and see if you get an error.

    Also in your echo, you're using things like $row['img'] - yet this is inside a double quoted string so you will get a warning about that. Remove the single quotes - they're not needed inside a string.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The problem is that mysql_fetch_* is designed to return false when its complete. Adding the or die in there means when you've iterated the entire recordset, the final occurrence causes it to issue a die.
    Remove the or die from the mysql_fetch_array.

  • #5
    New Coder
    Join Date
    May 2011
    Location
    UK
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Arrow

    Quote Originally Posted by Fou-Lu View Post
    The problem is that mysql_fetch_* is designed to return false when its complete. Adding the or die in there means when you've iterated the entire recordset, the final occurrence causes it to issue a die.
    Remove the or die from the mysql_fetch_array.
    Thanks for the reply. I'll try this when I get back into work tomoz.

  • #6
    New Coder
    Join Date
    May 2011
    Location
    UK
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The error message has gone now but it still wont show the contents i know there is content,

    Database dispair_db
    Table structure for table slideshow
    Column Type Null Default
    ID int(11) No
    brand varchar(30) No
    img varchar(75) No
    desc text No

    Dumping data for table slideshow
    1 Albion /images/AW12/albion-bordeaux.png Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium arcu non velit. Phasellus adipiscing auctor lorem. Curabitur in urna ut purus consequat sollicitudin. Phasellus ut diam. Cras magna libero, tempor id, venenatis sit amet, venenatis et, dui.

    this is the content yet it wont show it from the code which is similar to the code above except all names in lower_case and i have removed the "or die()"

    any advice would be helpful

    if you want me to repost the code again let me know

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    You fixed the upper/lower case problems ... and
    there is no column called "Details" ... $row['Details'],
    so you also fixed that ...

    can you repost your script now since you fix things?



    .

  • #8
    New Coder
    Join Date
    May 2011
    Location
    UK
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    include '/database/config.php';
    include '/database/open.php';

    $query = 'SELECT * FROM slideshow';
    $result = mysql_query($query) or die('Query Error: '.$query .'<br /><br />'. mysql_error());

    while($row = mysql_fetch_assoc($result))
    {

    echo " <div class='slide'>
    <h2>".$row['brand']."</h2>
    <p><a href='#'><img src='".$row['img']."' alt='An image that shows the ".$row['brand']." style shoe' width='215px' height='145px' border='0' /></a>"
    .$row['desc']."</p>
    </div>
    ";
    };
    include '/database/close.php';

    i fixed it all now the error was a mis type i had a ; at the end of the while before the {

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Ah yes didn't even notice that.
    ; at the end of a while loop is true once and only once on the last iteration.
    For an example:
    PHP Code:
    <?php

    $a 
    range(110);
    while ((
    $cur current($a)) && next($a) or die('all done'));
    {
       print 
    $cur PHP_EOL;
    }
    Will simply execute the die. If you remove the semi-colon, it will print 1-9 then die. The next() is the bound check on this one, so it will never make it to the 10.


  •  

    Posting Permissions

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