Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Displaying all images in Database table using PHP

  • 16-03-2006 04: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