Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:38 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.