Jump to content
Larry Ullman's Book Forums

Need Help About Pagination In Chapter 9


Recommended Posts

Hi I'm in a very early stage of learning PHP and mySQL and I really like this book "PHP 6 and MySql 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)"! I read through the whole book and it solved lots of my headaches.

 

I tried to create a News list page with pagination code in Chapter 9 in page 278, but it didn't work so far. The problem is the page is not showing any error notices or anything, it only shows a blank page! And I really can't find anything wrong with the code...Wish my problem can be solved. Here is the code:

 

<?php

$page_title = "Event & Press News";

echo 'Event & Press News';

ini_set('display_errors', 1);// displaying errors = true

error_reporting(E_ALL);// show all types of errors

 

require_once('../mysqli_connect.php');

 

 

//Number of records to show per page:

$display = 10;

 

//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(id) FROM News";

$r = @mysqli_query ($dbc, $q);

$row = @mysqli_fetch_arrary ($r, MYSQLI_NUM);

$records = $row[0];

 

//Calculate the number of pages...

if ($records > $display){//More than 1 page.

 

$pages = ceil($records/$display);

 

} else {

 

$pages = 1;

 

}

 

}// 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;

}

 

// Make the query.

$q = "SELECT * FROM News ORDER BY id ASC LIMIT $start, $display";

$r = @mysqli_query($dbc, $q);

 

if (mysqli_num_rows($r) > 0){

 

//Fetch each news headlines

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

$title = $row['title'];

$id = $row['id'];

echo '

<p> <a class="style32" href="news.php?id='.$id.'">'.$title.'</a>

</p><hr />';

 

}//End of WHILE loop;

}else {

echo 'There are currently no News in the Gallery website';

}

 

mysqli_free_result ($r);

mysqli_close($dbc);

 

//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="event-press-test.php?s='.($start - $display).'&p='.$pages.'">Previous</a> ';

}

 

// Make all the numbered pages:

for ($i = 1; $i <= $pages; $i++){

if ($i != $current_page) {

echo '<a href="event-press-test.php?s='.(($display * ($i - 1))).'&p='.$pages.'">'.$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="event-press-text.php?s='.($start + $display).'&p='.$pages.'">Next</a>';

}

echo '</p>'; // Close the paragraph.

} // End of links section.

 

?>

 

 

Many thanks!!

Link to comment
Share on other sites

First two things are:

 

1) Is that path to the required file definitely correct?

 

2) One line 23 you've misspelt a function name:

 

$row = @mysqli_fetch_arrary ($r, MYSQLI_NUM);

Should be...

 

$row = @mysqli_fetch_array ($r, MYSQLI_NUM);

 

Check those first and let us know if it fixes things.

Link to comment
Share on other sites

It's working perfectly now!!! It's the misspelling messed up everything!! Thank you so much Stuart!!!

 

First two things are:

 

1) Is that path to the required file definitely correct?

 

2) One line 23 you've misspelt a function name:

 

$row = @mysqli_fetch_arrary ($r, MYSQLI_NUM);

Should be...

 

$row = @mysqli_fetch_array ($r, MYSQLI_NUM);

 

Check those first and let us know if it fixes things.

Link to comment
Share on other sites

 Share

×
×
  • Create New...