|
-
Dec 5th, 2009, 10:12 PM
#1
Thread Starter
Addicted Member
[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 ?
-
Dec 5th, 2009, 10:27 PM
#2
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.
-
Dec 5th, 2009, 10:37 PM
#3
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
-
Dec 5th, 2009, 10:54 PM
#4
Thread Starter
Addicted Member
Re: .jpg file in php and mysql
 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.
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 ?
-
Dec 6th, 2009, 12:46 AM
#5
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; ?>" />
 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.
-
Dec 6th, 2009, 02:21 AM
#6
Thread Starter
Addicted Member
Re: .jpg file in php and mysql
 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.
i m confused now.... i am using dreamweaver cs3 and my sql and php....do u guys know of any tutorial for this....?
-
Dec 6th, 2009, 03:33 AM
#7
Re: .jpg file in php and mysql
confused about what..?
post your code if you'd like some help with something.
-
Dec 6th, 2009, 05:17 AM
#8
Re: .jpg file in php and mysql
 Originally Posted by kows
you basically said exactly what I did then.
After, I re-read what I posted yes, I am agreeing with you.
 Originally Posted by learnvb1
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
-
Dec 7th, 2009, 04:24 AM
#9
Thread Starter
Addicted Member
Re: .jpg file in php and mysql
Thanks guys...it is all working now
-
Dec 8th, 2009, 03:39 AM
#10
Thread Starter
Addicted Member
Re: .jpg file in php and mysql
 Originally Posted by Nightwalker83
 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
-
Dec 8th, 2009, 09:55 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|