Welcome, Guest: Join Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,777,631 members, 6,618,208 topics. Date: Monday, 06 December 2021 at 04:42 AM

Please Help Me In This PHP Pagination Code - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Please Help Me In This PHP Pagination Code (976 Views)

Learn Awesome Pagination Design Using Only HTML & CSS / Help With This Php Problem / Jquery Pagination Plugin (2) (3) (4)

(1) (Reply) (Go Down)

Please Help Me In This PHP Pagination Code by Falisto: 6:40pm On Aug 05, 2018
Hi, Good Nairaland programmers, I want you to help me in this PHP pagination code. It is always giving out error message whenever i click at the next link.
please help me to look at it and help me to make corrections.
Thanks.

The code is here below:

<?php

// Get the search variable from URL
if(isset($_POST['SUBMIT'])){
$professionals = $_POST['profession'];
$country = $_POST['country'];
} elseif(isset($_GET['_xp'],$_GET['_xs'])){
$professionals = $_GET['_xp'];
$country = $_GET['_xs'];
}

// rows to return
$limit=10;
$professionals = $_POST['profession'];
$country = $_POST['country'];

//connect to your database ** EDIT REQUIRED HERE **
$conn = mysql_connect("localhost","profes13_members","notebook8a1c"wink;
$db = mysql_select_db("profes13_list", $conn);
//specify database ** EDIT REQUIRED HERE **



// Build SQL Query
$s = (isset($_GET['s']))? $_GET['s']:0;
$query = "select * from members where profession ='$professionals' order by RAND() "; // EDIT HERE and specify your table and field names for the SQL query

$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);

// If we have no results, offer a google search as an alternative

if ($numrows == 0)
{
echo "<h4>Results</h4>";
echo "your search returned zero result<br>";

echo"<a href = 'memberusage.php'>CONTINUE SEARCH HERE</A>";


}

// next determine if s has been passed to script, if not use 0
$s = (isset($_GET['s']))? $_GET['s']:0;

// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query"wink;

// display what the person searched for


// begin to show results set
echo "Results";

$count = 1 + $s ;

// now you can display the results returned
while ($row= mysql_fetch_array($result))
{
$username = $row["username"];
$name =$row['name'];
$gender =$row['gender'];
$profession = $row['profession'];
$pics = $row['pics'];
$num = "($count&nbsp)";

echo $num;
?>
<img src= "<?php echo $pics; ?>" alt="Nigerian Directory of Professionals" width="70" height="70" /><br />

<b>Name</b>::<b><font color="#009933"> <?php echo $name ?></font></b><br />
<?php

echo "<a href='profile.php?id=" . $username . "'> "."".""." View $name's profile </a><br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";



$count++ ;
}

$currPage = (($s/$limit) + 1);

//break before paging
echo " <br />" ;

// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print "&nbsp;<a href=\"" . $_SERVER['PHP_SELF'] . "?s=$prevs&_xp\">&lt;&lt;
Prev 10</a>&nbsp&nbsp;";
}

// calculate number of pages needing links
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}

// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

// not last page so give NEXT link
$news=$s+$limit;


echo "&nbsp;<a href=\"" . $_SERVER['PHP_SELF'] . "?s=$news&_xp\">Next 10 &gt;&gt;</a>";
}


$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;


echo "<p>Showing results $b to $a of $numrows</p>";
?>
Re: Please Help Me In This PHP Pagination Code by dragnet: 6:49pm On Aug 05, 2018
post the errors you're getting, those who want to help you can interprete and make corrections or suggestions.
Re: Please Help Me In This PHP Pagination Code by Bolaji21(m): 5:01pm On Aug 06, 2018
For starters, change from mysql to mysqli, it'll most likely not work cos it's been depreciated in php 5 and removed in php 7.
Secondly, try to adapt this pagination function to your taste

function pagination ($con,$page_id,$query,$ppage=20)
{
global $pagination,$page,$lastpage;
$adjacents =3;

/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$wweck = mysqli_query($con,$query); //update current user time left
$total_pages=mysqli_num_rows($wweck);

/* Setup vars for query. */
$targetpage = $page_id; //your file name (the name of this file)
$limit = $ppage; //how many items to show per page
$page = isset($_GET['page']) ? $_GET['page'] : 0;
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0

/* Get data. */
$result = mysqli_query($con,$query." LIMIT $start, $limit"wink;

/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1

/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev\">< previous</a>";
else
$pagination.= "<span class=\"disabled\">< previous</span>";

//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
}

//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\">next ></a>";
else
$pagination.= "<span class=\"disabled\">next ></span>";
$pagination.= "</div>\n";
}
return $result;
}
Re: Please Help Me In This PHP Pagination Code by Falisto: 6:41pm On Aug 08, 2018
Ok. Ill try it. Thanks.
Re: Please Help Me In This PHP Pagination Code by Ayemileto(m): 12:48pm On Aug 09, 2018
What's the exact error you are getting?

(1) (Reply)

Microsoft Visual Studio Enterprise2017 Worth Ard $1200. Is Up At A Cheap Price / I Want To Learn Hacking / How To Change Wordpress To Php

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2021 Oluwaseun Osewa. All rights reserved. See How To Advertise. 99
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.