close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Mysqli Pagination

Thread began 12/15/2018 7:02 am by Kumel | Last modified 1/03/2019 1:49 pm by Ray Borduin | 267 views | 14 replies |

Kumel

Mysqli Pagination link problem.

I have following code based on your tutorial on MYSQLI Numbered pagination:

<?php
$maxRows_Properties =4;
$Properties = new WA_MySQLi_RS("Properties",$con2,$maxRows_Properties);
$Properties->setQuery("SELECT * FROM Properties");
$Properties->execute();
?>
<?php
$PropertiesTotal = new WA_MySQLi_RS("PropertiesTotal",$con2);
$PropertiesTotal->setQuery("SELECT count(1) a FROM Properties");
$PropertiesTotal->execute();
$Properties_Total = (int)$PropertiesTotal->Results[0]['a'];
$Req_Pages = ceil($Properties_Total/$maxRows_Properties);
?>

<?php

$totalRows_Properties = $Properties_Total;

$pageNum_Properties = 0;
if (isset($_GET['page'])) {
$pageNum_Properties = $_GET['page'];
}

$incdone = false;
if ($maxRows_Properties == 0)
{
$maxRows_Properties =1;
$incdone = true;
}

$totalPages_Properties = ceil($totalRows_Properties/$maxRows_Properties)-1;


if($totalPages_Properties > 0 && !$incdone )
{
$elems = array();
for ($i=0;$i<$Req_Pages;$i++)
{
if ($i==$pageNum_Properties)
{

$elems[] = "<li><a class=\"current-page\" href=\"properties.php?page=$i\">".($i+1)."</a></li>";
}
else
{
$elems[] = "<li><a href=\"properties.php?page=$i\">".($i+1)."</a></li>";
}
}



echo implode(" ",$elems);
}
?>




I want to use properties.php?page=1 or 2 or 3 & so on rather than pageNum_Properties.

Numbering works. But results display ain't changing.

Sign in to reply to this post

Ray BorduinWebAssist

You can probably just add code to the top of the page (above the recordset) like:

php:
<?php

if (isset($_GET["page"])) {
  
$_GET["pageNum_Properties"] = $_GET["page"];
}
?>
Sign in to reply to this post

Kumel

Seems to work. thanks.

Btw i have following sql for the Properties table

SELECT ....
FROM Properties INNER JOIN Units ON Units.UnitPropertyID = Properties.PID GROUP BY Properties.PID ORDER BY Units.UnitName ASC, Units.UnitSize ASC



And for PropertiesTotal when I use the above SQL, pagination is not visible.

this works & display pagination:

.. FROM Properties INNER JOIN Units ON Units.UnitPropertyID = Properties.PID  ORDER BY Units.UnitName ASC, Units.UnitSize ASC


Why is it so when i use GROUP IN SQL for Total it doesnt work.

Sign in to reply to this post

Ray BorduinWebAssist

I'd need to see the full SQL statement and describe what you are trying to achieve vs the result you are seeing to explain anything. Using GROUP will change the number of results. It shouldn't effect weather pagination works, but it would effect how many pages there are.

Maybe pagination isn't showing because there isn't more than one page.

Sign in to reply to this post

Kumel

this sql is right. its used for repeating properties.

SELECT Properties.PID, Properties.PName, Properties.PArea, Properties.PCategory, Properties.PPricepsqft, Properties.PMainimage, Properties.PPosition, Units.*
FROM Properties INNER JOIN Units ON Units.UnitPropertyID = Properties.PID GROUP BY Properties.PID ORDER BY Units.UnitName ASC, Units.UnitSize ASC
Sign in to reply to this post

Ray BorduinWebAssist

Please provide a URL to reproduce the issue and FTP access and I can look into why the pagination doesn't work.

Sign in to reply to this post

Kumel

I havent uploaded online uet.. Once done. will update the link here.

Sign in to reply to this post

Kumel

Well i didn't want numbering system. hence fine with "next" "prev".

But i got a doubt.

<?php if ($Properties->PageNum > 0) { // Show if mysqli not first page ?>
<li style="padding:20px;"><a class="prev" href="<?php echo $Properties->getPrevPageLink(); ?>">Previous</a></li>
<?php } // Show if mysqli not first page ?>
<li><a class="next" href="<?php echo $Properties->getNextPageLink(); ?>">Next</a></li>

Now here default on using it works. i want the link to be seo friendly, so how to make link appear like page.php?page=1. Rather than page.php? pageNum_Properties=1 & so on.

Sign in to reply to this post

Ray BorduinWebAssist

I doubt it would make an SEO effect unless you think someone will be googling the term "page", but you could use str_replace() to replace the parameter in the url like:

php:
<?php echo str_replace("pageNum_Properties=","page=",$Properties->getPrevPageLink()); ?>


Then on the top of the page change it back in the php above the recordset like:

php:
<?php

if (isset($_GET["page"])) $_GET["pageNum_Properties"] = $_GET["page"];
?>
Sign in to reply to this post

Kumel

Hi,

I m facing issues with pagination. PVT MSG.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...