Forum Moderators: coopster

Message Too Old, No Replies

Page rotator without leaving the actual page...

A couple of coding bugs I need to fix.

         

sauce

5:07 pm on Jun 25, 2005 (gmt 0)

10+ Year Member



Hi, I'm trying to write a homepage page rotator. The home page is default.php and I want 3 pages to rotate in that file without leaving default.php or directing to the actual pages I'm rotating... Basically, a content rotator but I want the content to be individual pages.

Here is what I have but it seems I have a bug somewhere:

<?
$pages = array(
include(page1.php),
include(page2.php),
include(page3.php)
);

shuffle($pages);
$i=0;
$number=2; while(list(, $page) = each($pages)) {
if ($i>=$number) { break; }
echo "$page";
echo '<br>';
$i++;
}
?>

For some reason the pages aren't coming up right in the default.php page.

Any help on this would be grealy appreciated.

sauce

dreamcatcher

5:47 pm on Jun 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Sauce,

Firstly, you need to enclose your pages in apostrophes:

<?
$pages = array(
include('page1.php'),
include('page2.php'),
include('page3.php')
);

Then if all you want is one random file, simply do

shuffle($pages);

echo $pages[0];

Hope that helps.

dc

sauce

8:01 pm on Jun 28, 2005 (gmt 0)

10+ Year Member



Dreamcatcher, I forgot to add the ' in my post but I did what you suggested and it just displayed... all 3 pages on top of each other... what am I missing here. This script seems so simple and is bugging the heck out of me! You gotta love programming ;)

sauce

mykel79

11:18 pm on Jun 28, 2005 (gmt 0)

10+ Year Member



You could try it like this:

<?
$pages = array(
'page1.php','page2.php','page3.php');
shuffle($pages);
include($pages[0]);
?>

Here the $pages array just holds the names of the files and you include a random one.

mcibor

8:59 am on Jun 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem was here:
$pages = array(
include('page1.php'),
include('page2.php'),
include('page3.php') );

You included the pages, so they are already processed - you don't echo include, as include doen't give output. Use the mykel's way instead - notice he includes only one file, not all three.

Hope this explained things a bit

Best regards
Michal Cibor

dreamcatcher

11:08 am on Jun 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, mcibor is correct. Sorry about that, for some reason I was just seeing it as a string.