paulman888888 Posted April 26, 2008 Share Posted April 26, 2008 Am trying to make a games page. Each game is on a diffecent page. I want to create a master page that includes all the sub pages and am trying to use an array to include them but I only want 10 shown at a time. The reason am useing an array is that i don't want to keep updateing the master page. Thankyou for the help Link to comment https://forums.phpfreaks.com/topic/103026-array-include-php-help/ Share on other sites More sharing options...
LemonInflux Posted April 26, 2008 Share Posted April 26, 2008 what, so, like this? <?php // Your array $pages = array('game1', 'game2', 'game3'); // Loop through the array, and include each one foreach($pages as $page) { include_once("games/$page"); } ?> That sort of thing? Link to comment https://forums.phpfreaks.com/topic/103026-array-include-php-help/#findComment-527725 Share on other sites More sharing options...
Fadion Posted April 26, 2008 Share Posted April 26, 2008 The code above will work but not show 10 at a time. Instead u can use a for loop: <?php for($i=0; $i<10; $i++){ include('games/' . $pages[$i]); } ?> That will work for the first 10 pages of the array. If u want your pages to be random or anything else, specify it here. Link to comment https://forums.phpfreaks.com/topic/103026-array-include-php-help/#findComment-527751 Share on other sites More sharing options...
paulman888888 Posted April 27, 2008 Author Share Posted April 27, 2008 One more thing. I would like to have a button when clicked picks out a random game. Thank-you for the help Paul Link to comment https://forums.phpfreaks.com/topic/103026-array-include-php-help/#findComment-528257 Share on other sites More sharing options...
paulman888888 Posted April 27, 2008 Author Share Posted April 27, 2008 <?php for($i=0; $i<10; $i++){ include('games/' . $pages[$i]); } ?> it doesn't work, it comes up with Warning: main(games/): failed to open stream: No such file or directory in /home/www/civage.com/games.php on line 89 Warning: main(games/): failed to open stream: No such file or directory in /home/www/civage.com/games.php on line 89 Warning: main(games/): failed to open stream: No such file or directory in /home/www/civage.com/games.php on line 89 Warning: main(): Failed opening 'games/' for inclusion (include_path='.:/usr/local/lib/php') in /home/www/civage.com/games.php on line 89 Please help Thankyou all Link to comment https://forums.phpfreaks.com/topic/103026-array-include-php-help/#findComment-528261 Share on other sites More sharing options...
Fadion Posted April 27, 2008 Share Posted April 27, 2008 It is supposed that u have a $page array which contains all the pages u want to include: $pages = array('mypage1.php', 'somepage.php', 'etc etc'); And use the right include path, the provided one is an example. Link to comment https://forums.phpfreaks.com/topic/103026-array-include-php-help/#findComment-528313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.