Wrox Programmer Forums
|
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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 August 22nd, 2007, 07:36 AM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page 77 - Not sorted alphabetically

Hi, I was trying out the exercise "Using the While function" and everything work fine except when I check the sort checkbox the list is not sorted alphabetically. Maybe because its numbered? Am I doing anything wrong.

Here's the PHP code I typed for the two files involved

moviesite.php
Code:
<?php
session_start();
//check to see if user has logged in with a valid password
if ($_SESSION['authuser'] != 1) {
    echo "Sorry, but you don't have permission to view this page, you loser!";
    exit();
}
?>
<html>
<head>
<title>My Movie Site - <?php echo $_REQUEST['favmovie']; ?></title>
</head>
<body>
<?php include "header.php"; ?>
<?php
$favmovies = array ("Life Of Brian",
                    "Stripes",
                    "Office Space",
                    "The Holy Grail",
                    "Matrix",
                    "Terminator 2",
                    "Star Wars",
                    "Close Encounters of the Third Kind",
                    "Sixteen Canldes",
                    "Caddyshack");

if (isset($_REQUEST['favmovie'])) {
  echo "Welcome to our site, ";
  echo $_SESSION['username'];
  echo "! <br>";
  echo "My favorite movie is ";
  echo $_REQUEST['favmovie'];
  echo"<br>";
  $movierate = 5;
  echo "My movie rating for this movie is: ";
  echo $movierate;
} else {
    echo "My top ". $_POST["num"] . " movies are:<br>";

    if (isset($_REQUEST['sorted'])) {
        sort($favmovies);
    }
    //list the movies
    $numlist = 1;
    while ($numlist <= $_POST["num"]) {
        echo $numlist;
        echo ". ";
        echo pos($favmovies);
        next($favmovies);
        echo "<br>\n";
        $numlist = $numlist + 1;
    }

}
?>
</body>
</html>
movie1.php
Code:
<?php
session_start();
$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;

//Check username and password information
if(($_SESSION['username'] == 'Joe') and 
   ($_SESSION['userpass'] == '12345')) {
    $_SESSION['authuser'] = 1;
} else {
    echo "Sorry, but you don't have permission to view this page, you loser!";
    exit ();
}
?>
<html>
<head>
<title>Find My Favorite Movie!</title>
</head>
<body>
<?php
  $myfavmovie = urlencode("Life Of Brian");
  echo "<a href='moviesite.php?favmovie=$myfavmovie'>";
  echo "Click here to see information about my favorite movie!";
  echo "</a>";
  echo "<br>";
  echo "Or choose how many movies you would like to see:";
  echo "</a>";
  echo "<br>";
?>
<form method="post" action="moviesite.php">
  <p>Enter number of movies (up to 10):
    <input type="text" name="num">
    <br>
    Check here if you want the list sorted alphabetically:
    <input type="checkbox" name"sorted">
    </p>
    <input type="submit" name="Submit" value="Submit">
  </form>
</body>
</html>
Alexander Lenner





Similar Threads
Thread Thread Starter Forum Replies Last Post
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
order XML file alphabetically bcogney XML 2 April 18th, 2006 01:45 PM
alphabetically sort drop down menu crmpicco Javascript How-To 0 August 2nd, 2005 05:03 AM
sorting a column alphabetically Adam H-W SQL Server 2000 8 November 11th, 2003 09:29 AM





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