|
|
|
|
![]() ![]() |
Jan 14 2006, 12:29 AM
Post
#1
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 575 Joined: 9-May 05 From: Oshawa, Ontario, Canada, North America, Planet Earth, Our Sun's Orbit, Milky Way Galaxy, The Universe, Beyond Member No.: 6,839 |
I'm learning php in class right now, but I'm still not that good at it, what I'm wondering is when I write the php so that it can connect with a database, can I at the same time have it that it is able to display back images that I choose.
Like, I want a search feature, where you can search for a keyword, and it will bring back a list of all the possible entries with that keyword, but each of these entries will have a photo associated with it. Now, do I put these image files directly into the database, or do I write the code to link them from my files to the other information that will be stored in the database? I've looked in Google, and around this forum, but can't really find what I'm looking for. Any suggestions? |
|
|
|
Jan 14 2006, 01:44 AM
Post
#2
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 630 Joined: 12-August 05 From: Melbourne, Australia Member No.: 10,624 |
I have done something like this with my site http://www.mudmall.com The database contains lnks to each of the images. I suggest you use thumbnails and limit the number of images shown on each page. I wrote the code myself and because I have taught myself it may not follow the correct conventions, therefore I won't show you the code unless you ask for it. I don't want to teach you any bad habits.
|
|
|
|
Jan 14 2006, 02:05 AM
Post
#3
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,880 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
I roamed around at the my_sql site and could find no reference to storing actual images in the Database, but like Avalon said, the best you will probably come up with is to use the DB to store the Image name, maybe a reference Number and other info about the image. I don't think Databases store the right amount or type of data to be able to store an actual image format.
|
|
|
|
Jan 14 2006, 02:24 AM
Post
#4
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 575 Joined: 9-May 05 From: Oshawa, Ontario, Canada, North America, Planet Earth, Our Sun's Orbit, Milky Way Galaxy, The Universe, Beyond Member No.: 6,839 |
That's pretty much what I'm after, Avalon, just with a couple different things like I want to have the date as a field as well.
I tried to convert my page to php, by I messed it up big time, and couldn't figure it out, so I'm trying again. Should I be getting the page to work in php first, and then try to add the database? Or do it all at once? What do you find works best? In class, the teacher just gives us a file, and basically tells us to change the variable names, so I haven't learnt much other than what I've taught myself either, but I'm way behind you lol... and hey, bad habits, aren't really bad habits so long as they get the job done. One thing my teacher does say is that it doesn't matter what means you take to get the job done with a client. So long as it works in the end, the client isn't going to know/care depending on how much they know about programming. |
|
|
|
Jan 14 2006, 05:15 AM
Post
#5
|
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 1,161 Joined: 9-May 05 From: Brisbane, QLD Member No.: 6,818 |
QUOTE(midnightvamp @ Jan 14 2006, 12:24 PM) I tried to convert my page to php, by I messed it up big time, and couldn't figure it out, so I'm trying again. Should I be getting the page to work in php first, and then try to add the database? Or do it all at once? What do you find works best? Get the page working in PHP first and then when that's right, you can replace actual values with those that come from the database. QUOTE(midnightvamp @ Jan 14 2006, 12:24 PM) One thing my teacher does say is that it doesn't matter what means you take to get the job done with a client. So long as it works in the end, the client isn't going to know/care depending on how much they know about programming. That's not strictly true. To say it doesn't matter what means you use is, quite frankly, irresponsible. For instance, you could set up a contact form on a site and through lax programming, leave it open to email header injection attacks so that your client's mail server gets used to transfer loads of spam. The client may never find about it but could gain a bad reputation as a spammer because the mail all appears to be coming from his/her email address. Or the client's web host may suspend or terminate the account due to the abuse. So, if you are doing paid work for a client, it is in your best interests to know as much as you can about what you're doing if you want to avoid having to pay to fix ealier errors, or worse still, be sued due to lost business caused by your oversights. |
|
|
|
Jan 14 2006, 11:10 AM
Post
#6
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 302 Joined: 17-June 05 From: Frankfurt, Germany Member No.: 8,358 |
hm there is also another possibilty to store image files in a data base apart from saving the link and some other info. what you can do is store the image in the database as a binary data. then you can have like lets say id be the primary key and have it auto increase and then you can call the image up with a small script to call the picture and then have it be like
CODE <img src="img.php?id=2"> for the second image in your database. i can show you the code if you want and its not a very big one either. it has an upload page and like an image.php page. you can password protect your upload page to prevent people messing around with it. and as for the search thing you can just add another column to your database table called Name or Keywords and then have a list of words in there and have a search thing where you have the mysql query WHERE $keyword or something like that. well not like that but thats how you would build up the code for searching. tell me if you want to try this and ill give you the code or if you dont understand something or yeah. |
|
|
|
Jan 14 2006, 01:53 PM
Post
#7
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 630 Joined: 12-August 05 From: Melbourne, Australia Member No.: 10,624 |
Yes you could store the images in the database as binary data, that's true. However, I think there are some major drawbacks in doing that, mainly with the size the database will become with each record being the equivalent size of the image itself. Correct me if I'm wrong, but I think that is what will happen. I also wonder what sort of load it will put on the server and how it will affect the speed of the database once more than a few records are added.
Tyssen is totally correct about learning to program correctly. If someone is teaching you, they should be teaching you the right way to do things, not just whatever will work. I also agree with Tyssen about the way to start. Decide on your layout, what fields you want to display and possibly use for calculations and then build your database and use those fields in your pages. The fields you see on my pages are not all the fields in the database. In the images table I also keep track of how many times an image is viewed at full size and the date it was last viewed. I have other tables for the banner accounts, searches and page view statistics. The fields and tables you use are totally up to you and what is needed to get the results you want. The database has evolved a little, originally I used to keep tracked of the image and thumbnail names, with careful naming of the thumbnails, I only need the image names. I also used to enter the image and file sizes of the images in the database, now I use php functions to calculate those on the fly. I could also use php to generate thumbnails on the fly, but I have chosen not to so I have a little more control over what is seen by visitors. Start simple and build from there, like any site, you will find it will evolve over time as you learn more. To start you with a few ideas, here is a link to the code (in a text file) for the page that lists the thumbnails based on search criteria. http://www.mudmall.com/other/list.txt As I said the code is most like not totally correct and there are probably more efficient ways of doing what I have done, but it does work. |
|
|
|
Jan 14 2006, 04:10 PM
Post
#8
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 436 Joined: 21-January 05 From: Koronadal City, Philippines Member No.: 3,358 |
Why don't you just insert the links to the images in your database? You can have a folder in your site where all the images are uploaded and you only need to store the location of the image in the database. If it's in the folder pictures you enter something like this in your database. "pictures/image1.jpg"
That way the actual data (flat string or numeric) is separate from your images. If you include the picture in the database, you will have problems with editing the pictures since it's not the usual text. You might also encounter format issues when querying from your database since you have to do some conversion to insert the data and to query or select data. |
|
|
|