Forum Moderators: coopster

Message Too Old, No Replies

PHP and MySQL image library

         

wonderboy

10:45 pm on Apr 27, 2004 (gmt 0)

10+ Year Member



Hi,

Just wondering the best way to do the following:

I have 6 categories of images, each manually updated with thumbnails and descriptions by me, however, I want the actual image page to be database driven, so all I would have to do is give each image a unique ID, decription, category, name (This name would appear next to category in browser title)

When you go to images.php?id=1 the image is called from database, with the relevant details being shown in the title of page, the header above picture and the description below picture.

Thanks for your help,

W.

hakre

9:23 am on Apr 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi wonderboy,

first of all you need to create your table with all the information about your images. i don't know how familiar you are with mysql, it would be good to know to make it more easy to help you.

to create and fill your table with data, i suggest you to use a database tool, because you don't need to use to type into the shell. awarded and widely used for this is phpmyadmin [phpmyadmin.net].

while you fill your table with data (don't forget your index), i would rename the images according to the index (i.e. photo-dog.jpg -> image00001.jpg). because of this, you can easily get the filename for the image afterwards based on your id-parameter (see below).

then you need to create a php file that queries your table and aquires the data needed for the image specified by the id parameter (

images.php?[b]id[/b]=1
). this is a step by step example, how it can be done:

1.) connect to your database server: mysql_connect() [php.net]

2.) select your database (every table is in a specific database): mysql_select_db() [php.net]

3.) the you need to build a query and run it agains your database. for this you need to know some simple basics about sql (it's a pretty simple query) and the according php-mysql function: mysql_query() [php.net]

4.) if your query is executed successfully (mysql_error() [php.net] returns infos if sth. went wrong) you can aquire the data (title,description, etc.) by using mysql_fetch_array() [php.net].

5.) last but not least, you need to display this data then. because of php you're free where to put it (header, below the image etc.).

--hakre

wonderboy

2:49 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



Hi Hakre,

I have made the database, and it works! the variables show up nicely in the destination page, thanks for your pointers!

I now need save extra records to the database from a webpage, I have created a form, but my INSERT code is not working on the processing PHP page, no errors happen, but nothing is added to the database.

Also, any ideas how to "add 1" to a number taken from the MySQL table, I have successfully taken the number out of database, and echoed it onto the page, but can't find the right command to add 1 to it!

Thanks again,

W.