473,411 Members | 2,230 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,411 software developers and data experts.

How can you pull a random item and leave that item on site for a specified time period?

I would like to pull a random or alphabetical result on the home page
of a site and leave that same result on there for one week. The
closest example I have found online is Random Quote Version 3.1 which
pulls from a text file rather than the database. I cannot mod it to
pull from my db and also it relies on cookies, so I would assume it
would pull a different random item for each computer and then keep
that item on the page for whatever time you specify (?). I am working
with dealers and would like to automatically feature a different
dealer every week without having to go into the db and choose which
one to feature. Is this possible using PHP and MySQL? Does anyone have
any suggestions on a different technology or maybe some links to help?

Oct 1 '07 #1
4 1757
<comp.lang.php>
<itcassy>
<Mon, 01 Oct 2007 17:19:48 -0000>
<11*********************@g4g2000hsf.googlegroups.c om>
I would like to pull a random or alphabetical result on the home page
of a site and leave that same result on there for one week. The
closest example I have found online is Random Quote Version 3.1 which
pulls from a text file rather than the database. I cannot mod it to
pull from my db and also it relies on cookies, so I would assume it
would pull a different random item for each computer and then keep
that item on the page for whatever time you specify (?). I am working
with dealers and would like to automatically feature a different
dealer every week without having to go into the db and choose which
one to feature.
<?php

$temp=time()+604800;

# the above is TIME NOW plus one week

# save $temp to database or flat file

?>

<?php

# grab $temp from database or flat file

$rambo=time();

if ($rambo>$temp) {print "One week has passed - select another dealer";}

?>
--
www.vhit.co.uk
Oct 1 '07 #2
On Oct 1, 1:47 pm, Krustov <m...@privacy.netwrote:
<comp.lang.php>
<itcassy>
<Mon, 01 Oct 2007 17:19:48 -0000>
<1191259188.218679.86...@g4g2000hsf.googlegroups.c om>
I would like to pull a random or alphabetical result on the home page
of a site and leave that same result on there for one week. The
closest example I have found online is Random Quote Version 3.1 which
pulls from a text file rather than the database. I cannot mod it to
pull from my db and also it relies on cookies, so I would assume it
would pull a different random item for each computer and then keep
that item on the page for whatever time you specify (?). I am working
with dealers and would like to automatically feature a different
dealer every week without having to go into the db and choose which
one to feature.

<?php

$temp=time()+604800;

# the above is TIME NOW plus one week

# save $temp to database or flat file

?>

<?php

# grab $temp from database or flat file

$rambo=time();

if ($rambo>$temp) {print "One week has passed - select another dealer";}

?>

--www.vhit.co.uk
Thanks for the quick response! However, I am not sure this will work.
Maybe I can clarify... I want the page to automatically choose a
different dealer to display automatically every week. Just like a
random sort except not every time you load the page, I only want the
code to choose a new dealer every week. If I save the temp time to
the db, it would only work once (?) for the first week? Please
correct me if I am not following....
Oct 1 '07 #3
<comp.lang.php>
<itcassy>
<Mon, 01 Oct 2007 17:56:53 -0000>
<11*********************@d55g2000hsg.googlegroups. com>
Thanks for the quick response! However, I am not sure this will work.
Maybe I can clarify... I want the page to automatically choose a
different dealer to display automatically every week. Just like a
random sort except not every time you load the page, I only want the
code to choose a new dealer every week. If I save the temp time to
the db, it would only work once (?) for the first week? Please
correct me if I am not following....
Yes i know what you want - but theres no way for anybody but yourself to
know how much or how little php skills you have - some people only need
a pointer and some people need more help .
At the end of the week - just repeat the $temp process to pick another
dealer to be shown - then repeat again the next week etc .

Assuming you have 50 dealers .....

$batman=(rand()%50);

This will pick a number between 0-49

If dealer number 22 is picked then store dealers name No. 22 in the
database or a flat file .

Then retrieve the dealers name from the database or flat file anytime
the index.php is loaded - and anytime it does this - then check the
$temp to see if its older than one week old .
--
www.vhit.co.uk
Oct 1 '07 #4
On Mon, 1 Oct 2007 18:47:54 +0100, Krustov <me@privacy.netwrote:
><comp.lang.php>
<itcassy>
<Mon, 01 Oct 2007 17:19:48 -0000>
<11*********************@g4g2000hsf.googlegroups. com>
>I would like to pull a random or alphabetical result on the home page
of a site and leave that same result on there for one week. The
closest example I have found online is Random Quote Version 3.1 which
pulls from a text file rather than the database. I cannot mod it to
pull from my db and also it relies on cookies, so I would assume it
would pull a different random item for each computer and then keep
that item on the page for whatever time you specify (?). I am working
with dealers and would like to automatically feature a different
dealer every week without having to go into the db and choose which
one to feature.

<?php

$temp=time()+604800;

# the above is TIME NOW plus one week

# save $temp to database or flat file

?>

<?php

# grab $temp from database or flat file

$rambo=time();

if ($rambo>$temp) {print "One week has passed - select another dealer";}

?>
Whatever you do, do not follow Krusty's variable naming style.
--
Regards, Paul Herber, Sandrila Ltd. http://www.sandrila.co.uk/
Oct 1 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Paul Rubin | last post by:
http://www.nightsong.com/phr/python/sharandom.c This is intended to be less predicable/have fewer correlations than the default Mersenne Twister or Wichmann-Hill generators. Comments are...
23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
18
by: kittikun | last post by:
Hi all, I was wondering if there is a random generator that is "reversible". I need to go back in time in my application and still need to use deterministic random numbers. Most of RNG implement...
16
by: jason.cipriani | last post by:
I am looking for a random number generator implementation with the following requirements: - Thread-safe, re-entrant. - Produces consistently reproducible sequences of psuedo-random numbers...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.