SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2001
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can Images be inserted into Mysql Databases???

    Please can anyone tell me if there is a way in which I can create a seperate table that holds just images.
    The table will need to match a profile table which I have already created but I need the php to call the data from the profile table and also an image from the image table..

    I know it can be done with asp but can it be done with mysql and php???

    As you can probaly tell from this I am totally new to php and mysql for that matter any feedback would be greatly appreciated...

    Thanks....

  2. #2
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sapper,

    Here's what I'd suggest:

    Have a MySQL table set up with the following fields:
    • ID
    • Image
    • Date
    • Anything Else
    Then, have all of your images stored in a directory (let's call it "sapperimages"). Now, in PHP, have the code look something like:
    PHP Code:
    print "<img src="/sapperimages/".$Image."\n"; 
    Now, I use a different style of calling info from a database then most people, but that should give you the general idea.

    Good luck!
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2001
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanx for the rapid response

    Thanx for the advise I will try that and get back to you....



  4. #4
    SitePoint Enthusiast
    Join Date
    May 2001
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am currently setting up the table as suggested by Corbbmacc I only require the two fields which are the id number and the image.

    The id number which will match the profile number but for the image field what type does it need to be???

    Do I need to put the image name or the path to it?????

    I did say I was new lol...


    Thanks again...

  5. #5
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's up to you. If you are having one image for each profile you don't actually need an image field - simply save the relevant image on your web server as X.jpg where X is the ID number of the profile. That way you don't need to have any reference to the image in the database.

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2001
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Skunk can you elaborate a bit on that as that is how my images are already stored matching the $memid field.

    So how would I call the images can you show me the call up line????

    would it be something like this

    print "<img src="/gfx/".$memid"n

  7. #7
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's possible to store the whole image in your mysql db, figure out the ads script op phpwizard.net, I installed that script and I remarked all images were stored in my db...
    But I don't know how to do that

  8. #8
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Skunk can you elaborate a bit on that as that is how my images are already stored matching the $memid field.

    So how would I call the images can you show me the call up line????

    would it be something like this

    print "<img src="/gfx/".$memid"n
    It would be something like print '<img src="/gfx/'.$memid.'.jpg"'; the file extension can be .gif etc. so if $memid is 5 it would be <img src="/gfx/5.jpg">

  9. #9
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Sapper
    Skunk can you elaborate a bit on that as that is how my images are already stored matching the $memid field.

    So how would I call the images can you show me the call up line????

    would it be something like this

    print "<img src="/gfx/".$memid"n
    If you call the images like this, make sure they all have the same format: ie, all of them should be JPG, or all GIF, or all PNG...
    Then you just do
    PHP Code:
    print "<img src=\"/gfx/".$memid.".jpg\">"
    If you don't use JPG, then just change the extension in the line
    [blogger: zengun] [blogware contributor: wordpress]

  10. #10
    SitePoint Enthusiast
    Join Date
    May 2001
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all the input guys,

    I will let you know if they work.....

  11. #11
    SitePoint Enthusiast
    Join Date
    May 2001
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tried the above and although it is now looking for an image it is not getting the number from the database.

    When clicking on the properties of the empty pic box it is pointing to the right directory just no number ie..

    http://www.mydomain.com/gfx/.jpg


    This is line that I am using to pull the file number so I really want it to appear next to it.


    printf("<br>Account Number: %s<hr>\n",
    $row["memid"]);
    print "<img src=\"/gfx/".$memid.".jpg\">";


    Thanks for all the help now who wants the glory by fitting the last piece to this puzzle lol

  12. #12
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you first have to pull the information from the database.

    Code:
    <?php
    //connect to database
    
    $query=mysql_query("select * from TABLE where 1=1"); 
    //select the data from a table in the database
    
    if (!mysql_Numrows($query)>0) { 
    //if nothing is found print an error message
    echo"No results found";
    }
        if (mysql_Numrows($query)>0) { 
    //if there are results found do something with it
    
            $numrows=mysql_NumRows($query);
            $x=0;
            while ($x<$numrows){ 
    $memid=mysql_result($query,$x, id); 
    //for each row of data found in the results, assign the 
    //(image) id to the memid variable and
    
    //print an image link for each 
    printf("<br>Account Number: %s<hr>\n", $memid); 
    print "<img src=\"/gfx/".$memid.".jpg\">"; 
    
    $x++;
            }
    }
    
    ?>
    Last edited by zoordaan; May 28, 2001 at 16:10.

  13. #13
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Sapper
    I have tried the above and although it is now looking for an image it is not getting the number from the database.

    When clicking on the properties of the empty pic box it is pointing to the right directory just no number ie..

    http://www.mydomain.com/gfx/.jpg


    This is line that I am using to pull the file number so I really want it to appear next to it.


    printf("<br>Account Number: %s<hr>\n",
    $row["memid"]);
    print "<img src=\"/gfx/".$memid.".jpg\">";


    Thanks for all the help now who wants the glory by fitting the last piece to this puzzle lol
    I don't blame you for not spotting this - it's an oddity to do with PHP's dynamic type system (whereby it tries to figure out what the "type" of a variable should be whenever it's used). You need to force PHP to treat $memid as a string even though it comes out of the database as an integer. You can do that like this:
    PHP Code:
    print "<img src=\"/gfx/".(string)$row["memid"].".jpg\">"
    Hope that helps,

    Skunk


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
  •