Images from a database, Multiple images per page
Posted by Honk (Honk), 13 September 2007Im having some trouble with the script to to place into and retrive images from a database. Im trying to use this in conjunction with a script to repeat 5 or so entries per page (like a blog) but only the first image appears. I only have a basic knowledge of php and have no idea what im doing wrong lol. heres the code I have so far
what I have so far can be viewed here.
I'm using Pid to create unique instances each time I dont know if this is the correct way to do this but it seemed the logical way ^^.
any help would be appreciated.
Posted by admin (Graham Ellis), 15 September 2007For starters, you need to generate either an image or HTML in each request to the script - not both; you have a mixture there. Basically, I'm afraid you have a lot of the right code but a major structural change needed back to how it was done in the original - your script appears to be loosely based on my original at http://www.wellho.net/solutions/php-example-php-form-image-upload-store-in-mysql-database-retreive.html
Have a look at the tips and techniques at the bottom of that original web page to help you .. and get the original working first. Then adapt and adopt slowly, step by step. Although short, this script glues together a graet many subjects and isn't trivial.
Posted by Honk (Honk), 16 September 2007Hey thanks for the reply.
I did adapt this from your script, taking it in steps (I got it working from scratch and then took out the pieces I needed until I merged it with the script I have now) and the script I have does work. The problem is that only the first image is showing up.
Im guessing now the problem I have is that this code
is only running the once and that would explain why only the first image is showing up. but placing this code outside the first ?> (where the HTML code which will be repeated however many times is) makes all the images fail.
Posted by admin (Graham Ellis), 17 September 2007That code you quote must run only once - you can only produce one image per request of the server; you'll note that in my original there was an exit command directly after the print bytes;, and that the script as a whole ran once to generate the HTML (no gim parameter), then again with gim parameters to generate the images. There are links in the first (HTML) output of the <img src=?gim=6 style to call up each image.
To get the script to work for you, modified, as a single piece of PHP to generate the whole web page, you;re best advised to revert to my scheme. As a reelative newcomer, you would probably find it much easier to use different PHP scripts for the HTML and for the Images.
I'm glad to read that the script sample was working until you made a series of incremental changes. Have a very careful look back at what you did at the point that the program ceased to work as you expected
Posted by Honk (Honk), 17 September 2007so would it be possible to generate more then one image per page from thi script? I'm guessing it would just not with this script but a whole new one lol. And I dont have the experience to write scripts from the top of my head as of yet
tis a shame as I was looking for a php solution that would allow a user from a simpliefied control panel to upload an image..most systems to upload were complex and would still require a reference from or to the database that would make the idea of a simple control panel useless as the user would have to search for complex information. The idea of adding the image directly into the database made things much easier! shame I cant get it to work ^^
Posted by admin (Graham Ellis), 18 September 2007on 09/17/07 at 12:07:06, Honk wrote:
There in nothing at all to stop you modifying the part of the script that generates the HTML to produce a whole loop of <img ...> tags, each of which runs the script again to produce an image. That is exactly what the other sample script that's referenced for my original document does - have another look at it
If you have a script that is nearly working then, yes, there are a few occasions you may want to start from scratch if it is fundamentally flawed. But I don't think that this one is, and I think you have little chance of getting the system working easily as you want by throwing it away in frustration and starting again. That approach would be a far longer road.
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho