Do someone can tell idea about this - images in PHP

First of all, I want to thank everyone of you (in the sitepoint forum, and the sitepoint as well), because due to you all, I have completed my first School project, and got 1st prize for it in my school.

This time, I want to develop 1 more thing,
Can someone please give me some idea about this?

I am making my new project for school, (All School Records in my city).
I know a little PHP and MySQL,

There will be the need for pictures of all schools, one school may have 50 or even more pictures of it, and another may have only 5 photos (depending upon their physical area).

So, is there any easy way to store the picture locations in the MySQL database.

I mean currently, I can save the picture locations in the database but, every-time, I have to alter the table for doing that, if I get a new photo for that school.

But what I want is, something like only 1 column is created in the MySQL database, and there will be no alterations in the table further, if I add new photo to any school.

Just, it would be added to the database.
And when I call them on web page using PHP, arrays could also be used for that.

But, I am totally new in this kind.

Can someone help.

Being it a 1 to many relationship, you need another table, for example called ‘pictures’, which will contain 0 to n pictures (1 picture per row) for each school. A possible table layout may be:


where schoolid+picture would be the primary key, and presuming schoolid would be the primary key of your existing school info table.

Oops Sorry Sir,
I didn’t get that.

If it already has stored one picture url in it, how it could be possible to store another url in the same column-row.

It’s not possible. And it’s not what I said:

The easiest implementation you can have is:

  1. Each school has a unique identifier in the database (ID).
  2. Using this number you create a folder with the ID as name.
  3. All photos for this school go into that folder
  4. Upon requesting the gallery for display, you can retrieve them only by using the ID
  5. Loop the directory to get the files

i.e.: /images/1/01.jpg, /images/1/02.jpg

And you don’t have to store a thing about images.

Steve Sir, you are also right, but I don’t want to store images on my own server, it will be on some photo sharing sites, that’s why their URL must be entered in the Database.

I just understood the way by Sir guido2004.

He means, to store the photos, by ID, (Like If ID=1 has 20 photos, so, I must store them by referring them as of ID=1).
This is very good sir if we don’t have photos stored on our server.

Thanks to you both, guido2004 Sir and Steve Sir.

What guido2004 says is that you need a different table for the images. This table
will have these fields: schoolID, image_url. Where schoolID is the ID of the schools table.
School’s will have their own table.

Yes Sir, you are right.

I just got a new Idea about this,
How about if I have one column named ‘pictures’ in the same table, no extra table needed.

ANd will update every record, if new picture is added, into new line of that record in MySQL.

And at the time of fetching, fetch it as an array.
SO that all images would be fetched into an array.

Is this right?