storing/retrieving images

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

storing/retrieving images

Post by Stelios »

Hi,

I am working on project where a user is searching for songs and after a successfull query a new page is popping up with the song title and other details. I would like on the same page to display images and a download link for the specific song. I am using php/mysql. Is this possible and if yes, is there any tutorial that might explain how to do this thing? I am new to php/mysql so any suggestions would be appreciated.

Thanks a lot! :D
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

- You should have at least 2 tables - 1 for the song data, 1 for the image locations.
- For each entry in the image table, store the ID of the song for which it is intended.
- I'd recommend putting file locations in the db rather than the image data itself, it'll be faster.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Yea, it's possible.

One way you could do this is make it so that when you add a song to your database you specify an image to go along with the song. That image will be uploaded to the server and then the name & location of that image would be stored in the same table that holds the song information. Then when you display results for a certain song you can display whatever image has been specified in that row.

Does that kind of make sense?

I Don't know if there are any tutorials that will tell you how to do exactly that, but you should be able to find tutorials on how to get each step done.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

It is absoloutly possible, however it is vital that you learn php and mysql first. From what I know there is no tutorials describing how to create that type of code. Mabey im wrong...
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

Hi again,

I am trying to do what you say nigma. The thing I dont know is how to map a file path when iserting data to the database.For example when I add a name its attribute would be varchar, how can I do this with file paths?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Same thing - varchar. What you want to store here is the same thing you'd put in an XHTML page when creating a link to an image. So, in your page, if you'd make the link:

Code: Select all

<img src = "/images/10275.jpg">
Then you'd put "/images/10275.jpg" in the db. You can then just dump that field into the page and the link should work.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply