display image using filepath from database
Results 1 to 5 of 5

Thread: display image using filepath from database

  1. #1
    Member
    Join Date
    Apr 2012
    Posts
    38

    display image using filepath from database

    I have a database table called 'uploads' that has filepaths to uploaded images in a 'filepath' column.

    i want to be able to display these images, 1 at a time( with some kind of 'next' and 'previous' button to come at a later date) on a page.

    so i know i need to connect to the database as usual and then query it, and then display the result of this query within an img tag, but besides from this i dont know the exact method and what ive got so far doesnt work. database connection has happened further up the script..
    PHP Code:


    <?php

    $result
    =mysql_query("SELECT 'filepath' FROM 'uploads'");  

    ?>

    <img src="<?php echo($result)?>" />
    can somebody give me some help with this please,
    thanks!

  2. #2
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,763
    What you are looking for to get the next/prev working is called Pagination, search for it on google or on these forums there's TONS of discussions on it.

    As far as the snippet you showed, you are trying to echo a resource. You need to fetch the rows you just queried for (in this case with mysql_fetch_array) then output from there.

    Also note the entire mysql_* library has been deprecated in favor of MySQL[i] (the i stands for improved) or PDO. See http://php.net/manual/en/mysqlinfo.api.choosing.php for more info.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  3. #3
    Senior Member
    Join Date
    Mar 2009
    Posts
    802
    Just to quickly touch on the pagination, you're probably going to use the MySQL limit clause. Click here to read more about it (you'll have to scroll down a bit to find it, or use ctrl-f).

    MOD EDIT: Anchor added to URL so that no scrolling is needed.
    Last edited by bradgrafelman; 04-10-2012 at 10:26 AM.
    Declare variables, not war.

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,390
    Quote Originally Posted by rpsep2 View Post
    so i know i need to connect to the database as usual and then query it, and then display the result of this query
    Er.. are you sure about that? The code snippet you posted only has two statements but contains 3-4 errors (depending upon what you call an error as opposed to just bad practice).

    I only ask because it's rather pointless for us to try to direct you to resources about pagination (which has been discussed many times here at PHPBuilder - you might try doing a search for 'mysql pagination') if you're still having problems with sending queries and retrieving results.

  5. #5
    Member
    Join Date
    Apr 2012
    Posts
    38
    Quote Originally Posted by bradgrafelman View Post
    Er.. are you sure about that? The code snippet you posted only has two statements but contains 3-4 errors (depending upon what you call an error as opposed to just bad practice).

    I only ask because it's rather pointless for us to try to direct you to resources about pagination (which has been discussed many times here at PHPBuilder - you might try doing a search for 'mysql pagination') if you're still having problems with sending queries and retrieving results.

    i meant that i know i need to... just not 100% sure how hence the post



    looked at the mysql_fetch_array and it now works! thank you. now gunna go try and figure out pagination

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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