[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 ?
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.
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.
Re: .jpg file in php and mysql
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.
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 ?
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.
Re: .jpg file in php and mysql
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.
i m confused now.... i am using dreamweaver cs3 and my sql and php....do u guys know of any tutorial for this....?
Re: .jpg file in php and mysql
confused about what..?
post your code if you'd like some help with something.
Re: .jpg file in php and mysql
Quote:
Originally Posted by
kows
you basically said exactly what I did then.
:lol: After, I re-read what I posted yes, I am agreeing with you.
Quote:
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.
Re: .jpg file in php and mysql
Thanks guys...it is all working now
Re: .jpg file in php and mysql
Quote:
Originally Posted by
Nightwalker83
:lol: After, I re-read what I posted yes, I am agreeing with you.
Quote:
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
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);
}
?>