Calling images from MySQL using PHP
Hi there, does anyone know any good tuts for displaying images using php. The thing is, I have a site that i search for a part number and it displays the info, that i can do but for some reason im lost when it comes to the images.
Do i save them in a db
Do i save them as link and save the link in a db
I just dont really know where to start, im self taught php and so a little help would be much appreciated
thanks
Dan
dandixon
Junior Poster in Training
62 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
You can save images as data within a blob field. But to be honest, I'd stick with an image folder with a reference to the url in the DB.
images table
id (PK)
displayname (could be a false filename or title)
extension (file type, e.g. jpg/png/gif/svg)
tags (useful for searching)
description (useful for searching)
uploader_id (user id)
uploaded_timestamp (unix integer timestamp)
(etc)
This is how I usually set my db:
In order to stop duplicate files and overwriting:
1) Send form (with upload file and info on picture)
2) Add new entry to DB, filling in details from $_POST.
3) Get PK value from mysql_insert_id() function and rename the image file to "img_" & id value followed by the original extension.
4) All images now are named: img_1.gif, img_2.jpg, img_3.jpg, img_4.png etc.
Overwriting is no longer an issue. Replacing an image is more straightforward that it would suggest.
Anyway, you can do all this without using the 'id' method - just copy the proper filename to a filename field.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
i hear where you are coming from and a understand most of what you say it's just im not fluent in php and am not sure how to call files from a folder
dandixon
Junior Poster in Training
62 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
OK mate, I hear you, but I don't want to be acting the sap and do the work for you. Clue:
<img src="<?php echo $img;?>" ...(other attributes perhaps) />
Where the $img variable has come from the db. It's just a path and a filename.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Thnks guys for your help, by any means i dont want it doing for me becuase i really want to learn this, just the process in my head and the starting point like you have given me.
Really appreciate it, im going to go and right some code and ill let you know where i get to and if i hit any snags
thanks
dan:)
dandixon
Junior Poster in Training
62 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
thanks to you guys i've figured out the image problem i had and now opened a whole new can of worms. I think i overcomplicated it in my head but once i sat down and thrashed out the code it wasnt too bad.
the new problem which i may hav to make a new post for is i need to query the db and return a part number and model, but the thing is these results need to link a page where they are displayed fully
heres an example http://www.airsprings.com/search/airsprings
if u type in the bottom box W02-358 in returns 3 results which are in turn linked to a page where they display fully.
Im not asking for the code or anything doing for me but suggestions of the best way to go about this
thanks again for all your help
dandixon
Junior Poster in Training
62 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Hi Larry
I have had this problem before with terminology, by any means i dont want to break rules and i dont want any code writing for me becuase i want to to learn if not whats the point, i may as well just employ someone.
I just want to know some ideas about the best way to go about doing things and make sure i do them in the right order.
The best way for me to explain things is to go to the link that i posted http://www.airsprings.com/search/airsprings and type this "W02-358" without qoutes into the botto box, as you will see this brings multiple results, which is the point where i have got to in my own script, but then if you click one of the results it taks you to a page where it displays the entire details for that result.
I just need a few suggestions about how i would do the same
Thanks again for helping me and im sorry about the accent
Dan
dandixon
Junior Poster in Training
62 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Yeah it is just an example i found but its exactly what i want, thanks for the help.
Thats pretty much what im looking for, i got the form and query sorted it was just the hot link i was struggling with and the how by clicking on the hotlink i get it to to display the full details on another page or the "unique page" as you call it.
dandixon
Junior Poster in Training
62 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Thanks Larry, i think ive got it, spent most of the day rattling through code but it works the way i want it to. When its finished ill send you a link.
Just gotta design the site now:(
Thanks
Dan
dandixon
Junior Poster in Training
62 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0