Reply to Re: Random HTML snippets with PHP include?

Your name:

Reply:


Posted by Rik Wasmus on 02/02/08 03:29

On Sat, 02 Feb 2008 01:13:57 +0100, Kevin G. <kgibbons04@gmail.com> wrot=
e:

> Hello all,
>
> I have a flat HTML page with 3 distinct HTML tables, and I'm trying to=

> randomly display the tables when the page loads, without repeating.
> My idea is to use the PHP include() function to pull in the page
> content.
>
> So what I've done so far was broke the full page down into 3 static
> HTML files, each containing one of the tables. Then in the main index=

> page where I want to display the code randomly, I created a variable
> using the rand() function -- and then within my include statement I'm
> using the $rand variable to build the html filename to include.
>
> The problem is that while the page does *work*, the rand function only=

> returns one random number and hence all three tables on the page turn
> out to be duplicates. What I'm looking to do is make sure that all 3
> HTML files are included into the page, but with no repeating, and each=

> of the 3 will show randomly on page load.
>
> Here's an example of what I have currently: =

> http://www.mollymaguires.net/rotating_html/
>
> Not exactly a PHP guru, so any replies back regarding setting up an
> array or custom functions to handle this situation need to be
> explained pretty clearly :) Thanks in advance for any help!

Either just use 1 include (if they're numbered), if they have different =
=

names, use a switch statement:

$chosen =3D mt_rand(1,3);
switch($chosen){
case 1:
include 'first.php';
break;
case 2:
include 'second.php';
break;
case 3:
include 'third.php';
break;
default:
echo 'something went horribly wrong';
}


-- =

Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация