Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\a_upload\index.php on line 114

line 144: while($row = mysql_fetch_assoc($R))
    $count = 0;
    $Q = "SELECT (SELECT image_short_name FROM user) as `image_short_name`"
    .",`image_id`,`user_id`,`image_short_name`,`image`"
    ." FROM `image`"
    ." ORDER BY RAND()"
    ." LIMIT 5";
    $R = mysql_query($Q);

echo "
<!DOCTYPE html>
<html lang='en'>
    <head>
        <title>Upload site: browse through thousands of image!</title>
        <link rel='stylesheet' type='text/css' href='css/top_menu.css' />
        <link rel='stylesheet' type='text/css' href='css/all_css.css' />
    </head>
<body>
        <div id ='bg'>
            <div id='context'>

            <table  width='1000px' height='500px' cellpadding='45px'>                       
                <tr height='100px'>     
                ";

                 while($row = mysql_fetch_assoc($R))
                        {
                            //get user_id from image table
                            $user_id_r         = $row['user_id'];
                            $image_short_name_r = $row['image_short_name'];

                            //get user name from user table
                            $queryget = mysql_query("SELECT username FROM user") ;
                            $row2 = mysql_fetch_assoc($queryget);   
                            $user_name_db = $row2['username'];

                            echo "<td width='100px'>";
                            $image_db = $row['image'];
                            $src = "data:image/gif;base64," . $image_db;
                            echo" <a href=\"zoom.php?img={$row['image_id']}\"><img src=\"$src\" width='130px' height='130px' class='image_p' /></a>";
                            echo "<center id='image_name'><a href=\"zoom.php?img={$row['image_id']}\">" . $image_short_name_r . "</a></center>";
                            echo " <center id='image_name2'>by $user_name_db</center>";
                            echo "</td>";
                            $count++;
                            if($count == 5)       //5 rows
                            {
                                echo "</tr><tr height='100px'>"; // Start a new row at 6 cells
                                $count = 0;
                            }
                        }

    Two quotes from the [man]mysql_fetch_assoc[/man] manual page:

    For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

    Use of this extension is discouraged. Instead, the [man]MySQLi[/man] or [man]PDO_MySQL[/man] extension should be used. See also MySQL: choosing an API guide and related FAQ for more information.

      Write a Reply...