dark_mirage Posted April 11, 2008 Share Posted April 11, 2008 Hey guys, ive been creating a reasonably simple image upload site lately, the user can upload a maximum of ten images, the links to these images then get stored in a database. Each users' records consists of their username password etc, then the fields image1 - image10. I have a gallery page where users will be able to view other members' images, but on the main gallery page i would like there to be 2 small sections, 1 showing the 5 top viewed images, and 1 showing the 5 newest images. I really cant get my head around how to do this. I cant work out how to store how many times each image has been viewed, or which is the newest, and im also having trouble finding how to retrieve this info from the database. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/100707-solved-most-viewed-and-new-additions/ Share on other sites More sharing options...
GingerRobot Posted April 11, 2008 Share Posted April 11, 2008 Unfortunately, that is because your database structure is all wrong. You should read up on database normalization (this topic here should get you started) Basically, you need to have a separate table for your images. You can then store which user the image is for, the date it was updated, views etc for each image. If your unsure as to why this is so, consider what would happen with your current structure if you decided to increase the number of images allowed per user. Link to comment https://forums.phpfreaks.com/topic/100707-solved-most-viewed-and-new-additions/#findComment-515059 Share on other sites More sharing options...
benphp Posted April 11, 2008 Share Posted April 11, 2008 Add a field to the image table called "viewed". When a user hits the page: Select viewed from image. $viewed = $viewed+1 Update image set viewed = $viewed You can also have a date/time stamp in the image table, so you can sort by date. Link to comment https://forums.phpfreaks.com/topic/100707-solved-most-viewed-and-new-additions/#findComment-515061 Share on other sites More sharing options...
dark_mirage Posted April 11, 2008 Author Share Posted April 11, 2008 thanks for the quick replies both i think i see what your saying robot, so i need one table called 'uploads' for example, with the fields, 'user id', 'image url', 'viewed' and 'date submitted'. that shouldn't be too much of a problem, im gonna have to do my 'delete' script now though thanks a lot. ps. still open for any other easier suggestions if you have them -edit- on second thoughts, this is a much easier solution, its also gonna make my display and delete script a hell of a lot easier, thank you very much Link to comment https://forums.phpfreaks.com/topic/100707-solved-most-viewed-and-new-additions/#findComment-515077 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.