473,385 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with 'recently uploaded pictures'

Markus
6,050 Expert 4TB
I'm doing a little project (for my own benefit) which results in an image host.

I would like to make a section on the main page for a recently uploaded section.

I have access to php and MySQL.

Anyone got any ideas?

Thanks a bunch in advance.
Sep 15 '07 #1
8 1630
pbmods
5,821 Expert 4TB
Heya, Markus.

I'm assuming that you are storing either image files or just the paths to these files in the database (either is an acceptable solution).

Simply add a TIMESTAMP field to your images table:
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE
  2.         `Ext_ImageUploads`
  3.     ADD
  4.         `Util_Uploaded`
  5.             TIMESTAMP
  6.             NOT NULL
  7.             DEFAULT CURRENT_TIMESTAMP
  8.             ON UPDATE CURRENT_TIMESTAMP,
  9.     ADD
  10.         KEY
  11.             (`Util_Uploaded`)
  12.  
The cool thing about the TIMESTAMP type is that, when you set its ON UPDATE CURRENT_TIMESTAMP method, MySQL will automatically set this value to the current date/time whenever you add a row.

So you might not have to change your upload script at all!

Then, to find the most recent uploads:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.         *
  3.     FROM
  4.         `Ext_ImageUploads`
  5.     WHERE
  6.         DATE_SUB(NOW(), INTERVAL 7 DAY) < `Util_Uploaded`
  7.     ORDER BY
  8.         `Util_Uploaded` DESC
  9.     LIMIT 10;
  10.  
This query will show the latest 10 uploads within the last week.
Sep 15 '07 #2
Markus
6,050 Expert 4TB
Heya, Markus.

I'm assuming that you are storing either image files or just the paths to these files in the database (either is an acceptable solution).

Simply add a TIMESTAMP field to your images table:
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE
  2.         `Ext_ImageUploads`
  3.     ADD
  4.         `Util_Uploaded`
  5.             TIMESTAMP
  6.             NOT NULL
  7.             DEFAULT CURRENT_TIMESTAMP
  8.             ON UPDATE CURRENT_TIMESTAMP,
  9.     ADD
  10.         KEY
  11.             (`Util_Uploaded`)
  12.  
The cool thing about the TIMESTAMP type is that, when you set its ON UPDATE CURRENT_TIMESTAMP method, MySQL will automatically set this value to the current date/time whenever you add a row.

So you might not have to change your upload script at all!

Then, to find the most recent uploads:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.         *
  3.     FROM
  4.         `Ext_ImageUploads`
  5.     WHERE
  6.         DATE_SUB(NOW(), INTERVAL 7 DAY) < `Util_Uploaded`
  7.     ORDER BY
  8.         `Util_Uploaded` DESC
  9.     LIMIT 10;
  10.  
This query will show the latest 10 uploads within the last week.

Thanks a bunch man! :D
Sep 15 '07 #3
pbmods
5,821 Expert 4TB
Heya, Markus.

I understand you're having difficulties displaying the recently uploaded images. What seems to be the trouble?
Sep 16 '07 #4
Markus
6,050 Expert 4TB
Heya, Markus.

I understand you're having difficulties displaying the recently uploaded images. What seems to be the trouble?
MySQL isn't my strong point.

What i can't do now, is have the images displayed.

I'm not sure how i would go about getting the stored url aswell as ordering it with the timestamp-thingy-magig.

Does that make sense? Lol, i'm sorry.
Sep 16 '07 #5
pbmods
5,821 Expert 4TB
Heya, Markus.

Are you storing the image files in the database, or are they stored on the filesystem and you're storing the file names in the database?
Sep 16 '07 #6
Markus
6,050 Expert 4TB
Heya, Markus.

Are you storing the image files in the database, or are they stored on the filesystem and you're storing the file names in the database?
Yeh, i'm just storing the url to the images in the database and the actual images in a folder on the server.

:)
Sep 17 '07 #7
pbmods
5,821 Expert 4TB
Heya, Markus.

Good stuff.

Okay. You have two options:
  • You can define 'recent' as being within the last x days.
  • You can define 'recent' as being among the last x uploads.
  • You can define 'recent' as being a combination of the previous two.

Three options. You have three options :)

The last one I demonstrated in my first post, and the two previous ones are merely the same thing, minus the LIMIT clause or minus the WHERE clause, respectively.

Once you run the query, it's a simple matter of extracting your file paths and outputting a bunch of HTML img tags.
Sep 17 '07 #8
Markus
6,050 Expert 4TB
Heya, Markus.

Good stuff.

Okay. You have two options:
  • You can define 'recent' as being within the last x days.
  • You can define 'recent' as being among the last x uploads.
  • You can define 'recent' as being a combination of the previous two.

Three options. You have three options :)

The last one I demonstrated in my first post, and the two previous ones are merely the same thing, minus the LIMIT clause or minus the WHERE clause, respectively.

Once you run the query, it's a simple matter of extracting your file paths and outputting a bunch of HTML img tags.
Well, you see, this is my problem. I'm not sure how i would write the code.

You might give me an example and i could fill in my own info?

It'd be much appreciated.
Sep 17 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tihon | last post by:
Hello! I again need your help, just can't understand whats going on. Got this upload pictures form and it's having problem handling large files (~1.5 - 2 MB). Everything works fine if i just...
2
by: Dynamo | last post by:
Hi I am using a form to upload an image from my hard drive to my server but there is something amiss cause I am continually getting an error message "FTP upload has failed" This is my code ...
5
by: Bernard | last post by:
Hi, I have a problem with a CGI script (Perl) on a Win2000 server. The script is for sending E-cards and was written by Jason Maloney:...
2
by: tperri | last post by:
I'm familiar with the Data Controls, however what I have is a website where users can upload multiple pictures. I want to display these pictures in a table, that has 3 columns in each row, and...
2
by: Window_Frog | last post by:
Hello all. I may or may not be in the right place, but I definetely need help. I have built several sites using vbscript to access a simple MySQL database. My users are able to enter simple...
2
by: andrescasta | last post by:
Hello, i have a problem when i try to delete a file that i recently uploaded. To upload, i used the FileUpload, when i receive the file, i save it in a directory inside the virtual application...
6
by: aanund | last post by:
I don't know if I'm in the right place, or doing this properly, but I hope someone sees it anyway. I am a rookin i PHP, yet I have found this to be an efficient and useful scripting language for many...
3
by: muddasirmunir | last post by:
i am using vb6 and crystal report 10 i want to ask solution of one proble which i am facing in making report. first , in my programe i ask the user to give paramerter (range) of the data...
8
by: punk86 | last post by:
Hi, i been working on this codes but i keep getting broken links for the pictures. Im using apache. Need help for this please. I think its just the codes in my index.php is wrong and i do not know...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.