A little help with some PHP and MySQL

Soldato
Joined
28 Oct 2002
Posts
9,227
Location
Stockport / Manchester
Hey, wonder if anyone can help me...

I have a MySQL database which contains a list of filenames of images and captions that go with them. Using PHP I want to insert the captions as titles in the link of the correct image.

For example, in the db I may have test1.jpg with "This is a test". How can I get it to enter the title in the link using the filename as the reference? I mean I know how to enter the data itself into the page, but I don't know how to make it look at the filename of the link and enter the correct caption from the db.

eg <img src="test1.jpg" title="This is a test" />

Hope you understand what I mean!

Cheers.
 
Thanks for that, it gets me one step closer, but it not quite fully what I'm after.

It shouldn't get the filename from the db, thats already there in the html file. What I want it to do is see that filename in the file, check it against the ones in the db and then insert the related caption into the images title attribute.

Cheers.
 
Hmm I see what you mean, but I can't for the life of me figure out how to actually do it lol

Basically say I have 3 images on a standard page.

1.jpg
2.jpg
3.jpg

Then in the database I have the captions that go with some images. I want the script to look at the html file, see 1.jpg in it, find the caption for that in the database, then stick it in the html file as the images title.

Maybe I should have added I'm pretty new to this stuff! :p
 
Right now I have a basic page with some images in.

...<body>
<img src="1.jpg" alt="1.jpg" title="" />
<img src="2.jpg" alt="2.jpg" title="" />
<img src="3.jpg" alt="3.jpg" title="" />
<img src="4.jpg" alt="4.jpg" title="" />
</body>...

The db table "files"...

id, fn1 (the filename), tit1 (the title)
 
Not every image will have a caption and in the final version the images will not be put there manually but via a simple gallery script, so I can't have it put the src from the database.
 
joeyjojo said:
Create an array with the image filenames which you want on the page. You edit this bit to change which images are shown.

Beansprout said:
Add a field to the database called 'Caption' and put a 1 for images with captions and a 0 for images without :)

I don't want to enter every image (ie those both with and without captions) into the database. Say theres 5 images on a page, only 3 may have a caption. But I don't want to have to enter details for all 5.
 
Back
Top Bottom