Jump to content

[SOLVED] Most Viewed and New Additions


dark_mirage

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

thanks for the quick replies both :P

 

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 :P

 

thanks a lot.

 

ps.  still open for any other easier suggestions if you have them :P

 

-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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.