SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to trace out the image name

    Hello Guys,

    I need your help.I am having a folder say "folder1" on my server.
    In that folder there are jpgs or pdfs or doc.
    like
    "myphoto_G_G.jpg"
    "myphoto_G_G_G.jpg".
    "myphoto_K_K.jpg"
    "myphoto_K_K_K.jpg".
    "myphoto_G_G.pdf"
    "myphoto_K_K.pdf"

    But in my database table there is record of jpg and pdf i.e.
    "myphoto_G_G_G.jpg" , "myphoto_K_K_K.jpg" , "myphoto_G_G.pdf" and
    "myphoto_K_K.pdf"
    Now I want to display the images whose record is present in database.
    i.e. the images of "myphoto_G_G_G.jpg". and "myphoto_K_K_K.jpg".

    Could any one help how do i trace out the names in database.

    Thanks in advance.
    Barbara

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How is the relation between database and the image name? Have you stored the image names in the database? Assuming you have stored the image names in the database table:
    PHP Code:
    $res mysql_query("SELECT * FROM tablename");
    while(
    $rows mysql_fetch_array($res)){
    echo 
    "<img src=\"./folder1/" $rows['imagefildname'] . "\" />";

    Does this make sense??
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    Simulation Cricketer
    Join Date
    Sep 2004
    Location
    australia
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    barbara1712, rajug is correct. In case you don't understand it:

    You need to replace "tablename" with the name of the table in the database.
    You need to replace "imagefildname" with the name of the column the record is stored in.

    You also need to have made a connection to the database using mysql_connect and mysql_select_db (if you use MySQL) before running the query.

  4. #4
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks rajug.
    Yeah you are right I have stored the images and pdfs in my database table.

    i.e suppose there are 8 files in folder for user1.
    1)"myphoto_G_G.jpg"
    2)"myphoto_G_G_G.jpg".
    3)"myphoto_K_K.jpg"
    4)"myphoto_K_K_K.jpg".
    5)"myphoto_G_G.pdf"
    6)"myphoto_K_K.pdf"
    7)"myphoto_thumb.jpg"
    8)"myphoto_thumb_thumb.jpg"

    But in database table there are only 5 the records for the user1
    1)"myphoto_G_G_G.jpg"
    2)"myphoto_K_K_K.jpg"
    3)"myphoto_thumb_thumb.jpg"
    4)"myphoto_G_G.pdf"
    5)"myphoto_K_K.pdf"

    and I want to display only the images from the database table.
    here I am facing the prblem that how do I trace out the image name from folder that should match with the image name present in the database.

    I have tried with this query
    PHP Code:
    select attachment from table where attachment like '.jpg' or attachment like '.jpeg' 
    but no success.
    Barbara

  5. #5
    Simulation Cricketer
    Join Date
    Sep 2004
    Location
    australia
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    select attachment from table where attachment like '&#37;.jpg' or attachment like '%.jpeg'

    Perhaps? IIRC, % is the wildcard value for MySQL.

  6. #6
    SitePoint Addict Php_penguin's Avatar
    Join Date
    Aug 2004
    Location
    Colwyn Bay, Wales, UK
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rajug: use single quotes! Then you wouldn't need to escape the second set of double quotes.

    Babs: Are you trying to select only the records in the database which are images?
    If so try this:
    Code:
    SELECT * FROM table WHERE filename LIKE '&#37;.jpg' OR filename LIKE '%.jpeg'
    The files in the folder are pretty much irrelevant until you get round to displaying them. As long as the database is absolute (always contains the right records) then you could have a billion images in the folder and it would make no difference.

  7. #7
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try your query like this then:
    Oops your query does not have &#37; in like.
    PHP Code:
    select attachment from table where SUBSTRING_INDEX(attachment,'.'-1)='jpg' OR SUBSTRING_INDEX(attachment,'.',-1)='jpeg' 
    Otherwise your query seems to be fine.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  8. #8
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks battye,

    Yeah I have tried with your query with success . I forgot to use wildcard.

    Thanks people
    Barbara

  9. #9
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks rajug
    query gives error.Just a small change.and gives all correct records.
    PHP Code:
    select attachment from table where SUBSTRING_INDEX(attachment,'.',-1)='jpg' OR SUBSTRING_INDEX(attachment,'.',-1)='jpeg' 
    Thanks for information of SUBSTRING_INDEX() function in mysql.
    Barbara

  10. #10
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh ya one comma was left. I am sorry. anyway it works now that is good.

    Cheers!
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


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
  •