Results 1 to 11 of 11

Thread: [RESOLVED] .jpg file in php and mysql

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2009
    Posts
    135

    Resolved [RESOLVED] .jpg file in php and mysql

    Hi
    I am new at php and mysql. I am building a website for a grocery store. I am storing all the data in a table, but i am confused how to deal with .jpg files. Because all the products have a .jpg file assosicated in it. Any ideas how to incorporate that ?

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: .jpg file in php and mysql

    you just need to store a file name in your table for that item's image, or name your images according to the item's ID/name. then, you can store all of your product images within one folder (/images/products/, for example).

    you could have names like 1912.jpg -- or alternatively 1912_pillsbury_minipizzas.jpg if you would like the names to be somewhat intuitive as to what the image is.

    whatever you do, I would advise against trying to store the actual image file within the database.

  3. #3
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: .jpg file in php and mysql

    What I do is store the images in a temporary folder within the root directory while you need them and save the location of the file to the database instead of the file itself. So using knows example above I would put "/images/products/1912.jpg" in the database as a reference to which image is being used.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2009
    Posts
    135

    Re: .jpg file in php and mysql

    Quote Originally Posted by Nightwalker83 View Post
    What I do is store the images in a temporary folder within the root directory while you need them and save the location of the file to the database instead of the file itself. So using knows example above I would put "/images/products/1912.jpg" in the database as a reference to which image is being used.
    Thanks for that...but then how do i display the image along with data....

    example

    Product_name Oil
    image file oil.jpg


    and i stored the oil.jpg in ../images/oil.jpg

    now how do i display the details (dynamically ) to a webpage ?

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: .jpg file in php and mysql

    after retrieving the data from your table, you could do something like this (assuming you stored the image filename within $image_name):
    PHP Code:
    <img src="/images/<?php echo $image_name?>" />
    Quote Originally Posted by Nightwalker83
    What I do is store the images in a temporary folder within the root directory while you need them and save the location of the file to the database instead of the file itself. So using knows example above I would put "/images/products/1912.jpg" in the database as a reference to which image is being used.
    you basically said exactly what I did then.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2009
    Posts
    135

    Re: .jpg file in php and mysql

    Quote Originally Posted by Nightwalker83 View Post
    What I do is store the images in a temporary folder within the root directory while you need them and save the location of the file to the database instead of the file itself. So using knows example above I would put "/images/products/1912.jpg" in the database as a reference to which image is being used.
    i m confused now.... i am using dreamweaver cs3 and my sql and php....do u guys know of any tutorial for this....?

  7. #7
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: .jpg file in php and mysql

    confused about what..?

    post your code if you'd like some help with something.

  8. #8
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: .jpg file in php and mysql

    Quote Originally Posted by kows View Post
    you basically said exactly what I did then.
    After, I re-read what I posted yes, I am agreeing with you.

    Quote Originally Posted by learnvb1 View Post
    i m confused now.... i am using dreamweaver cs3 and my sql and php....do u guys know of any tutorial for this....?
    As kows said post your code and we will be able to help you better.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jul 2009
    Posts
    135

    Re: .jpg file in php and mysql

    Thanks guys...it is all working now

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 2009
    Posts
    135

    Re: .jpg file in php and mysql

    Quote Originally Posted by Nightwalker83 View Post
    After, I re-read what I posted yes, I am agreeing with you.


    As kows said post your code and we will be able to help you better.
    now it works but when i do the repeat region in dreamweaver it is not working....

    Code:
    <?php do { ?>
          <td><a href="display_details.php?product_id=<?php echo $row_Recordset1['product_id']; ?>"><?php echo $row_Recordset1['Name']; ?></a></td>
          <td><?php echo $row_Recordset1['category']; ?></td>
          <td><img src="images/<?php echo $row_Recordset1['image_name']; ?>" alt="image" width="228" height="91" /></td>
          <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </tr>
    </table>
    </body>
    </html>
    <?php
    it displays other values correctly but the image doesnt display for all the other values...it only displays for the first one

  11. #11
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: .jpg file in php and mysql

    uhh. you should be using a while loop, not a do loop. with just that code, the first record wouldn't even display because $row_Recordset1 is not set until after the first iteration through the loop. other than that, if your image_name isn't working, then either your files don't exist or you don't have the correct values in your database. it's a loop; if it works for one iteration, it works for every iteration.

    using a while loop:

    PHP Code:
    <?php
      $sql 
    "SELECT * FROM table WHERE ....";
      
    $query mysql_query($sql);

      while(
    $row mysql_fetch_assoc($query)){

        
    //dump all values
        
    print_r($row);

      }
    ?>

Posting Permissions

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



Click Here to Expand Forum to Full Width