Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Displaying all images in Database table using PHP

  • 16-03-2006 3:53pm
    #1
    Closed Accounts Posts: 252 ✭✭


    Hi guys,

    This is giving me a lot of problems. I am able to insert in images in a table, and display ONE image. But I want to display all the images in the table, this is me giving trouble, this code at the moment is displaying the same image ten times.

    As I am incrementing the $ID variable, I want different images to be displayed, but I just keep getting the same one. I do know it is working to some extent, when I put in this statement(echo $name; ) I do get all the image names.


    CODE

    <?

    $db = mysql_connect("******", "*****","*****");

    mysql_select_db("****",$db);

    $id = 1;
    while($id<10){
    $query = "SELECT name, type, size, content FROM upload where id ='$id'";
    $result = mysql_query($query) or die('Error, query failed');
    list($name, $type, $size, $content) = mysql_fetch_array($result);


    if ($_REQUEST[gim] == $id) {


    header("Content-length: $size");
    header("Content-type: $type");


    echo $content;

    exit;
    }






    ?>

    <html>
    <title>Upload an image to a database</title><body>

    <center><img src=?gim=<? echo $id ?> width=160 height=160><br>


    </body>
    </html>

    <?
    $id++;
    }
    ?>



    _______________________________
    Edit - I had pasted in the wrong version of the code, which was calling 1 as the value, rather than the incremented $id............this version seems to be calling the correct image address(gim=2 or gim=3 and so on) but isn't displaying the relevant image


Comments

  • Registered Users, Registered Users 2 Posts: 4,003 ✭✭✭rsynnott


    Well, for a start, don't store images in a table unless you've got a very good reason for it.


  • Registered Users, Registered Users 2 Posts: 249 ✭✭frost


    You aren't incrementing $id in your loop.


  • Registered Users, Registered Users 2 Posts: 919 ✭✭✭timeout


    You aren't incrementing $id in your loop.
    Well its in it now at the end.

    This is your problem
    where id ='$id'";
    should be
    where id=" . $id;
    
    OR
    where id='" . $id . "'";
    
    if you need the single quotes.


  • Registered Users, Registered Users 2 Posts: 249 ✭✭frost


    timeout wrote:
    Well its in it now at the end.
    Oops, missed that at the end!
    timeout wrote:
    This is your problem

    should be
    where id=" . $id;
    
    OR
    where id='" . $id . "'";
    
    if you need the single quotes.

    Should also work with curly braces:
    $query = "SELECT name, type, size, content FROM upload where id ='{$id}'";
    


Advertisement