473,564 Members | 2,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1767
<comp.lang.ph p>
<itcassy>
<Mon, 01 Oct 2007 17:19:48 -0000>
<11************ *********@g4g20 00hsf.googlegro ups.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()+60 4800;

# 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.n etwrote:
<comp.lang.ph p>
<itcassy>
<Mon, 01 Oct 2007 17:19:48 -0000>
<1191259188.218 679.86...@g4g20 00hsf.googlegro ups.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()+60 4800;

# 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.ph p>
<itcassy>
<Mon, 01 Oct 2007 17:56:53 -0000>
<11************ *********@d55g2 000hsg.googlegr oups.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.net wrote:
><comp.lang.php >
<itcassy>
<Mon, 01 Oct 2007 17:19:48 -0000>
<11*********** **********@g4g2 000hsf.googlegr oups.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()+6 04800;

# 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
3661
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 appreciated.
23
4160
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 initialize it with the same parameter. Can this be done with JavaScript? I couldn't find anything in the documentation. Basically, what I want to...
18
350
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 the Next function but what about a Prev ? I know I can use an array to store X last values but I'm more interested to know if it exist something...
16
539
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 given a seed. - Relatively uniform, does not have to be perfect. The application is not a security or statistics application, the quality of numbers...
0
7666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.