Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'ch9'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. Hi, I am having problems with pagination. I thought I had script 9.4 working without any problems, so carried on with script 9.5, which I also thought was working OK. I then added another table to my online database which I accessed by a script based on 9.5, but then I found the pagination wasn't working. I then found the pagination in script 9.5 wasn't working. The s and p appear in the url address line, and it would appear the code: if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } is ignored, as start always stays at 0 (or whatever value I put as $start = ). I've checked and double checked but can't see where the problem is. The full code is included here: ------------------------------------- <?php # Script 9.5 - view_users95.php // This script retrieves all the records from the users table. // This version allows the results to be sorted in different ways. // This version paginates the query results. $page_title = 'View the Current Users'; include ('includes/header8.html'); // Page header: echo '<h1>Registered Users 5</h1>'; require_once ('../mysqli_connect.php'); // Connect to the db. // Number of records to show per page: $display = 5; // Determine how many pages there are.. if(isset($_GET['p']) && is_numeric($_GET['p'])) { //Already been determined $pages = $_GET['p']; } else { // need to determine // count the number of records $q = "SELECT COUNT(user_id) FROM users"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // calculate the number of pages... if ($records > $display) { // More than 1 page. $pages = ceil ($records/$display); } else { $pages = 2; } }// end of p IF // Determine where in the database to start returning results if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Determine the sort... // Default is by registration date. $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'rd'; // Determine the sorting order: switch ($sort) { case 'ln': $order_by = 'last_name ASC'; break; case 'fn': $order_by = 'first_name ASC'; break; case 'rd': $order_by = 'registration_date ASC'; break; default: $order_by = 'registration_date ASC'; $sort = 'rd'; break; } // Make the query: $q = "SELECT last_name, first_name, DATE_FORMAT(registration_date, '%d %M, %Y') AS dr, user_id FROM users ORDER BY $order_by LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // Run the query. // Table header. echo '<table border="5" align="center" cellspacing="0" cellpadding="5" width="50%"> <thead><tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b><a href="view_users95.php?sort=ln">Last Name</a></b></td> <td align="left"><b><a href="view_users95.php?sort=fn">First Name</a></b></td> <td align="left"><b><a href="view_users95.php?sort=rd">Date Registered</a></b></td> </tr> </thead>'; // Fetch and print all the records: $bg = '#eeeeee'; // Set the initial background colour. while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { //$bg = ($bg=='#bbbbbb' ? '#ffffff' : '#bbbbbb'); // Switch the background colour, using the Ternary operator. echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_user93pw.php?id=' . $row['user_id'] . '">Edit</a></td> <td align="left"><a href="delete_user92pw.php?id=' . $row['user_id'] . '">Delete</a></td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['dr'] . '</td> </tr> '; } // end of while loop echo '</table>'; // Close the table. mysqli_free_result ($r); // Free up the resources. mysqli_close($dbc); // Close the database connection. //Make the links to other pages, if necessary if ($pages > 1) { // Add some spacing and start a paragraph echo '<br /><p>'; // Determine what page the script is on: $current_page = ($start/$display) + 1; // If it's not the first page, make a previous button: if ($current_page != 1) { echo '<a href="view_users95.php?s=' . ($start - $display) . ';p=' . $pages . ';sort=' . $sort .'">Previous</a> '; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="view_users95.php?s=' . (($display * ($i - 1))) . ';p=' . $pages . ';sort=' . $sort . '">' . $i . '</a> '; } else { echo $i . ' '; } } // end of FOR loop // If it's not the last page, make a next button: if ($current_page != $pages) { echo '<a href="view_users95.php?s=' . ($start + $display) . ';p=' . $pages . ';sort=' . $sort . '">Next</a> '; } echo '</p>'; // close the paragraph } // end of the links section echo "<p>Users = $records.</p>\n"; // with this line in the pagination doesn't work echo "<p>Pages = $pages.</p>\n"; echo '<br />'; include ('includes/footerx.html'); ?> ----------------------------------- I hope you can shed some light on this problem Thanks Chris
×
×
  • Create New...