Re: Banner rotation with links
| From: | Jochem Maas | Date: | Thu, 15 Feb 2007 16:57:17 +0000 |
| Subject: | Re: Banner rotation with links | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248917@lists.php.net to get a copy of this message | ||
Kevin Murphy wrote:
> On my home page i have all my banners in a MySQL database which includes
> the image path, the link, and the description as separate fields. The
> then do a MySQL query with a query that will look something like this:
>
> $query = "select * FROM banner ORDER BY RAND() LIMIT 1";
>
> Seems to work just fine.
just wait till you have 100000 items in that table :-)
in practice that may never happen and maybe MySQL can optimize a
SELECT that does "ORDER BY RAND() LIMIT 1"
(can anyone confirm what MySQL does with "ORDER BY RAND() LIMIT 1" exactly in terms
of scanning the table? - the MySQL docs don't mention whether this is scalable at all)
*but* if that is not the case then using a field (call it 'randomized' or something like
that)
and indexing on that and then updating that field periodically with random
integers using a cronjob script would make the resulting query alot more robust ..
the compromise being that you don't get a different banner each request:
$query = "select * FROM banner ORDER BY randomized LIMIT 1";
the compromise can be mitigated some what by doing something like this
(assuming you use sessions):
// BRC = Banner Random Count
if (!isset($_SESSION['BRC']))
$_SESSION['BRC'] = 0;
$query = "select * FROM banner ORDER BY randomized LIMIT {$_SESSION['BRC']},1";
$_SESSION['BRC']++;
>
> --Kevin Murphy
> Webmaster: Information and Marketing Services
> Western Nevada Community College
> www.wncc.edu
> 775-445-3326
>
>
> On Feb 14, 2007, at 8:29 AM, Chris Carter wrote:
>
>>
>> How can I rotate a banner as well as the link in it within a page
>> using PHP.
>> This can be done as a include file php. Anybody please supply some
>> code or a
>> link for this.
>>
>> Thanks in advance.
>>
>> Chris
>> --View this message in context:
>>
>> http://www.nabble.com/Banner-rotation-with-links-tf3228157.html#a8968148
>> Sent from the PHP - General mailing list archive at Nabble.com.
>>
>> --PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>