?
Solved

problem with paging code,php

Posted on 2010-03-30
6
Medium Priority
?
218 Views
Last Modified: 2013-12-12
hi expert,i have paging code here but its not working anyone can help me..
paging.php
0
Comment
Question by:agilentwax
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:john-formby
ID: 29091208
On line 115, you have missed the semi-colon.  This line:

$showeachside = 5

should be:

$showeachside = 5;

Hope this helps,

John
0
 

Author Comment

by:agilentwax
ID: 29185715
thnks john-formby, its correct but the result i got so long..how to limit it..i want to make like this example
http://www.web-max.ca/PHP/misc_1.php..i want to display 10 Number of items to show either side of selected page..means only display  12345678910.....next not like in the pic
when click next it will be display like this PREV ...234567891011...NEXT..i have some code here but dont know how to combine it..i have try but got error



page.png
0
 
LVL 1

Accepted Solution

by:
mike_nguyen earned 2000 total points
ID: 29232690
I think when you determines how many pages you will need to render by running the simple calculation like

$numberofpage = ceil($totalrecords / $perpage);

Then, in your paging code, take the variable that determines your current page id + number of page you want to show, then run the query

for example:

$numberofpagetoshow  = $currentid + 10;
for ($i = $currentid; $i <= $numberofpagetoshow; $i++) {
      echo "<a href='#' ...>";
}

I hope this helps.

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:agilentwax
ID: 29753700
dear mike nguyen thnks for ur help..i have get what i need..but i have another problem here..
let say my paging result like this

123456789...

when i click 1 it go to index page(home page) not the result page for the page 1..how to change the code that when click 1 it go to page result 1..here my code for the paging page..

<td width="99" align="center"> 
<?php
if(($start-$limit) >= 0)
{
    $next = $start-$limit;
?>
<a href="<?php print("$thispage".($next>0?("?option=com_content&view=article&id=156&find=$find&region=$region&country=$country&city=$city&start=").$next:""));?>">PREV</a> 
<?php
}
?>
</td>
<td width="201" align="center" class="selected">
Page <?php print($cur);?> of <?php print($max_pages);?><br>
( <?php print($nume);?> records )
</td>
<td width="100" align="center" valign="middle" bgcolor="#EAEAEA"> 
<?php 
if($start+$limit<$nume)
{
?>
<a href="<?php print("$thispage?option=com_content&view=article&id=156&find=$find&region=$region&country=$country&city=$city&start=".max(0,$start+$limit));?>">NEXT</a> 
<?php
}
?>
</td>
</tr>
<tr><td colspan="3" align="center" valign="middle">&nbsp;</td></tr>
<tr> 
<td colspan="3" align="center" valign="middle" class="selected"> 
<?php 
$eitherside = ($showeachside * $limit);
if($start+1 > $eitherside)print (" .... ");
$pg=1;
for($y=0;$y<$nume;$y+=$limit)
{
    $class=($y==$start)?"pageselected":"";
    if(($y > ($start - $eitherside)) && ($y < ($start + $eitherside)))
    {
?>
&nbsp;<a class="<?php print($class);?>" href="<?php print("$thispage".($y>0?("?option=com_content&view=article&id=156&find=$find&region=$region&country=$country&city=$city&start=").$y:""));?>"><?php print($pg);?></a>&nbsp; 
<?php
    }
    $pg++;
}
if(($start+$eitherside)<$nume)print (" .... ");
?>
</td>

Open in new window

0
 

Author Comment

by:agilentwax
ID: 29756640
sori mike nguyen,,ignore my previous question..i have solve the problem
0
 
LVL 1

Expert Comment

by:mike_nguyen
ID: 29756958
Just want to show an alternative way
<tr>
    <td width="99" align="center">
        <?php
            if ($start != 1) { echo "Prev link with start = start - 1"; } //If the current page 1 export Prev link
                                                                          //If the current page is not 1 export prev link with start = start - 1 (for the previous page)
            
        ?>
    </td>

    <td width="201" align="center" class="selected">
        <?php
            echo "Page $start of $numberOfPages";
        ?>
    </td>
    <td width="100" align="center" valign="middle" bgcolor="#EAEAEA">
        <?php
            if ($start != $numberOfPages) { echo "Next link with page = page + 1"; } //If current page is not the last page show the next link
        ?>
    </td>
</tr>
<tr>
    <td colspan="3" align="center" valign="middle">&nbsp;</td>
</tr>
<tr>
    <td colspan="3" align="center" valign="middle" class="selected">
        <?php
            if ($start == 1) { //if you are at page 1, then print from one to limit. Limit is the number of page you want to show. For example, you want to show 7 page at 
                               //time then your limit is 7. 
                for ($i = $start; $i <= $start + $limit; $i++) {
                    echo "<a href='somefile.php?start=$i'>$i</a>";
                }
                echo "....";
            }
            elseif ($start == $numberOfPages) {  //If at the last page, add .... and then move from 7 from last page to last page
                echo "....";
                for ($i = $numberOfPages - $limit; $i <= $numberOfPages; $i++) {
                    echo "<a href='somefile.php?start=$i'>$i</a>";
                }
            }
            else {
                echo "....";
                for ($i = $start; $i <= $start + limit; $i++) { //print from current page to limit
                    echo "<a href='somefile.php?start=$i'>$i</a>";
                }
            }
        ?>
    </td>

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question