SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pulling image from DB script

    I recently read a tutorial on how to store images in my DB, when I got to the pulling part, it showed this as the way to do it:

    PHP Code:
    if($id) {

    // getdata.php3 - by Florian Dittmer

    @MYSQL_CONNECT("localhost","root","password");

    @
    mysql_select_db("Images");

    $query "select bin_data,filetype from Images where id="$id";
    $result = @MYSQL_QUERY($query);

    $data = @MYSQL_RESULT($result,0,"bin_data");
    $type = @MYSQL_RESULT($result,0,"filetype");

    Header( "
    Content-type$type);

    }; 
    then calling the image by linking the page this way:

    getdata.php3?id=#

    This way you MUST know the number of the image you want to pull, but I just want to pull the most recent image, how can I do that?

  2. #2
    SitePoint Evangelist AlexC's Avatar
    Join Date
    Oct 2000
    Location
    Sheffield, UK
    Posts
    437
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, This is a quick guess (i.e chances are it wont work)

    PHP Code:
    if ($action=='getnewest') {
    $query "select bin_data,filetype from Images limit 0,1 order by id";
    } else {
    $query "select bin_data,filetype from Images where id="$id";

    like i say, i'm not sure on it - it may work, it may not
    Nearly 7 years old!

  3. #3
    SitePoint Evangelist AlexC's Avatar
    Join Date
    Oct 2000
    Location
    Sheffield, UK
    Posts
    437
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OH yea,

    to call the newest image, use the url

    getdata.php3?action=getnewest
    Nearly 7 years old!

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by AlexC
    PHP Code:
    if ($action=='getnewest') {
    $query "select bin_data,filetype from Images limit 0,1 order by id";
    } else {
    $query "select bin_data,filetype from Images where id="$id";

    if he wants to get the highest number entry it would be:

    SELECT bin_data, filetype FROM Images ORDER BY id DESC LIMIT 1
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


Bookmarks

Posting Permissions

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