NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Generate random timestamp?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 08-30-2007, 11:26 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
DylanButler's Avatar
Join Date: Jan 2006
Location: San Diego, CA
Posts: 734
DylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to behold
 



Generate random timestamp?


how can I generate a random timestamp (between now and a few seconds from now / before now) with PHP?

PHP Code:
$this->db->Execute("UPDATE ".T_BANNERS." SET impressions=impressions+1, date_last_displayed=NOW() WHERE id=?",array($banner['id'])); 
????: NamePros.com http://www.namepros.com/programming/368481-generate-random-timestamp.html
That is my PHP that does the update. The problem is I am doing this multiple times quickly and the same date/time is getting inserted for each banner (we are updating banners here) which as a result is causing trouble randomizing banners to display.

What I want to do:

Create a random time (in seconds) from now and a few seconds in the future. Just enough time so the banners don't get the same date_last_displayed value in each row.


I have searched everywhere for an easy way to do this and most don't explain how to randomize time without treating it as a string.

Any help is greatly appreciated.
DylanButler is offline  
Old 08-31-2007, 05:21 AM   #2 (permalink)
NamePros Regular
 
geronimo's Avatar
Join Date: Aug 2007
Posts: 352
geronimo is a name known to allgeronimo is a name known to allgeronimo is a name known to allgeronimo is a name known to allgeronimo is a name known to allgeronimo is a name known to all
 



hi,

instead of "randomizing" your timestamp as you put it, you could order your data by the timestamp and id

Order by timestamp, id....

that way you will get the banners sorted in the correct order
geronimo is offline  
Old 08-31-2007, 06:44 AM   #3 (permalink)
NamePros Member
Join Date: May 2007
Posts: 56
Zurvan is an unknown quantity at this point
 



You can convert your timestamp to an integer, and create a random number & add it on to the time. No need to work with strings. Look at the time() function
Zurvan is offline  
Old 08-31-2007, 08:57 AM THREAD STARTER               #4 (permalink)
NamePros Regular
 
DylanButler's Avatar
Join Date: Jan 2006
Location: San Diego, CA
Posts: 734
DylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to behold
 



Originally Posted by geronimo
hi,
????: NamePros.com http://www.namepros.com/showthread.php?t=368481

instead of "randomizing" your timestamp as you put it, you could order your data by the timestamp and id

Order by timestamp, id....

that way you will get the banners sorted in the correct order
Yes thats exactly what I did to fix this, order by date_last_modified, rand()

and that seems to work. I just wanted to see how this would be done like the last poster said, by adding an integer.
DylanButler is offline  
Old 08-31-2007, 09:15 AM   #5 (permalink)
NamePros Regular
 
geronimo's Avatar
Join Date: Aug 2007
Posts: 352
geronimo is a name known to allgeronimo is a name known to allgeronimo is a name known to allgeronimo is a name known to allgeronimo is a name known to allgeronimo is a name known to all
 



fair enough, glad you fixed it.
geronimo is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:24 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger