Wrox Programmer Forums
|
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 27th, 2009, 12:31 PM
Registered User
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page 77 moviesite / arrays / while do

Not a problem, just a bit of info.

Working through this book, been OK so far.

The script on page 77 either shows the top x movies, or a sorted top x movies, however if you choose less than 10 you will get a different result back becuase the sorting sorts ths whole array, but the displaying only shows the first x amount.

So change the code to this:

Code:
	$subset = array_slice($favmovies, 0, $_POST["num"]);
	if (isset($_REQUEST['sorted'])) {
		sort($subset);
	}
print_r($favmovies);
echo "<br>";
echo "<br>";
print_r($subset);
echo "<br>";
echo "<br>";
	//list the movies
	$numlist = 1;
	while ($numlist <= $_POST["num"]) {
		echo $numlist;
		echo ". ";
		echo pos($subset);
		next($subset);
		echo "<br>\n";
		$numlist = $numlist + 1;
	}
And for 3, you will get back :

1. Life of Brian
2. Stripes
3. Office Space

And for 3 sorted you wil get back:

1. Life of Brian
2. Office Space
3. Stripes

Which makes more sense to me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Page 77 - Not sorted alphabetically alexlenner BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 August 22nd, 2007 07:36 AM
Ch3 Moviesite table already exists? aiche_ag BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 August 7th, 2007 01:29 PM
Chapter 2 Pg. 75-77 while function joshkosmala BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 February 28th, 2007 04:27 PM
moviesite login problem chapter 2 StuartD BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 August 15th, 2005 06:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.