Forum Moderators: coopster

Message Too Old, No Replies

Inserting images into a MySQL database

Newbie. How can I put my images into a MySQL table?

         

Francis

8:12 pm on Mar 29, 2003 (gmt 0)

10+ Year Member



Can you please help me because I wanted to insert images into my database and I'm following a tutorial. However, I can't seem to follow well enough to display the images. All that's happening is the filename is display. For example, one.jpg, two.jpg, etc.

Maybe you can help me:

1. Put the pictures in the database;
2. Display the pictures from the database;

Also, where would I put the pictures? Should the images be in the same directory as the php file or I have to specify in the database where it is coming from? Or does it work like Access wherein you can store the image together with the table?

The tutorial has something like:

// Display them to the screen...

echo "<a href=\"" . $row["link"] . "\">
<img src=\"" . $row["image"] . "\" border=0 alt=\"" . $row["text"] . "\">
</a>" ;

Where can I get an explanation for this? Can you please point me? It would be a big help. Thanks.

andreasfriedrich

8:25 pm on Mar 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might want to have a look at the Image upload and Thumbnail Generator [webmasterworld.com] in the Bag-O-Tricks for PHP II - some code snippets that should be helpful for all in creating dynamic sites [webmasterworld.com].

>>The tutorial has something like:

It is amazing how quite a few tutorials use rather bad codeing style. Who is supposed to understand this example. I havenīt got a clue and cannot be bothered to figure out which double quotes are actual string delitimers and which ones arenīt. Why do they use the concatenation operator when echo [php.net] will happily accept a list of strings?


echo "<a href=\"" . $row["link"] . "\">
<img src=\"" . $row["image"] . "\" border=0 alt=\"" . $row["text"] . "\">
</a>" ;

should be written as


echo <<<END_OF_IMAGE
<a href="{$row["link"]}">
<img src="{$row["image"]}" border=0 alt="{$row["text"]}">
</a>
END_OF_IMAGE;

Now that is easy to read and understand. Even


echo <<<END_OF_IMAGE
<a href="$row[link]}">
<img src="$row[image]" border=0 alt="$row[text]">
</a>
END_OF_IMAGE;

would have been ok although it is not as good as the former example.

>>Also, where would I put the pictures?

You can put the whole picture into a BLOB [mysql.com] or just store the image path in the db and move the pictures to some directory as the example script in the Bag-O-Tricks for PHP II - some code snippets that should be helpful for all in creating dynamic sites [webmasterworld.com] does.

Andreas

Francis

4:24 pm on Mar 30, 2003 (gmt 0)

10+ Year Member



ok. thanks for the help. let me try that out.