trying to display image from database. last image to 1st.

but getting error:
Warning: mysql_query() expects parameter 1 to be string, resource given in C:\xampp\htdocs\a_upload\gallery.php on line 12
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\xampp\htdocs\a_upload\gallery.php on line 26

    $sql = mysql_query("SELECT * FROM image WHERE user_id = $id");
    $result = mysql_query($sql); //get access to image table

while($row = mysql_fetch_assoc($result))
                            echo"<td> ";
                                    $image_db = $row['image'];
                                    $src = "data:image/gif;base64," . $image_db;
                                    echo" <img src=\"$src\" width='130px' height='130px' class='image_p' />";
                                    if($count == 5)       //5 rows
                                        echo "</tr><tr>"; // Start a new row at 6 cells
                                        $count = 0;

Recommended Answers

All 4 Replies

At a glance, I can see this issue:
Your code on line 1 executes the query "SELECT * FROM image WHERE user_id = $id". Then it stores the result of the query in $sql. On line two you're trying to execute another query, but you're passing it the result of the first one. Doesn't really make sense. Just get rid of line 2, and maybe change "$sql" in line 1 to "$result". That or get rid of "mysql_query(" and ")" on line 1.

thanks, do you know how can i change my $result so that iam geting image starting from last one?

Member Avatar

Post solved? Or is this question still live?

solved but thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.