TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-22-2007, 03:46 PM   #1 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Unhappy please check my code

this is a pagination--
Code:
if ($numrows > 3)	
{
<tr><td colspan="6" align="center" height="20" class="table-list-title"><b>Total selected transactions: &nbsp;<? echo $numrows?>&nbsp;</b>
	
		$s=$start+1;
		$l=$start+20;
		echo "Viewing $s - $l ";
	if ($start > 0)
		{
			echo '<span class="char"><A href="'; echo $_SERVER["PHP_SELF"]; echo '?click=client_list.php&menu=1&start=0&limit=20">[First] </a></span>';			
		} 
		$prev=$start-$limit;
		$next=$start+$limit;
		if ($prev >= 0){
		echo '<span class="char"><A href="'; echo $_SERVER["PHP_SELF"]; echo '?click=client_list.php&menu=1&start='.$prev.'&limit='.$limit.'">< Previous </a></span>';			
		}
		$numofpages=$numrows/$limit;
		if(($numrows % $limit)!=0)
		$numofpages=$numofpages+1;		
		for($i=1,$start=0;$i<=$numofpages;$i++)
		{
		$start=$start+$limit;
		$last=$start-$limit;
		}
		if ($next < $numrows){
		echo '<span class="char"><A href="'; echo $_SERVER["PHP_SELF"]; echo '?click=client_list.php&menu=1&start='.$next.'&limit='.$limit.'">Next ></a></span>';			
		}
		echo '<span class="char"><A href="'; echo $_SERVER["PHP_SELF"]; echo '?click=client_list.php&menu=1&start='.$last.'&limit='.$limit.'">[Last]</a></span>';	
}
please correct my code...make it simpler and short....i know this is an absolute beginner code..
meshi is offline  
Reply With Quote
Old 10-22-2007, 06:48 PM   #2 (permalink)
The Contributor
Upcoming Programmer 
 
Gurnk's Avatar
 
Join Date: Oct 2007
Location: US
Posts: 66
Thanks: 19
Gurnk is on a distinguished road
Default

What errors are you getting?
Send a message via MSN to Gurnk
Gurnk is offline  
Reply With Quote
Old 10-22-2007, 11:02 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Pagination, I'm afraid, is prone to having so much code - there isn't a really easy way to do it. One question, however, why do you have so many missing PHP tags?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-23-2007, 06:48 AM   #4 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Default

oh i see..i thought it has simplier solution than mine..thanx..
meshi is offline  
Reply With Quote
Old 10-23-2007, 10:47 AM   #5 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You could certainly clear out some of the unnecessary code, but the basic structure would be essentially the same.
Salathe is offline  
Reply With Quote
Old 10-30-2007, 05:15 PM   #6 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Default

ok thanx.:)
meshi is offline  
Reply With Quote
Old 10-30-2007, 07:43 PM   #7 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

PHP Code:
        function pagination($current_page$num_of_pages)
        {
                        if(
$current_page $num_of_pages)
                                
$current_page $num_of_pages;

                        if(
$current_page == "")
                                
$current_page 1;

                        if(
$current_page != 1)
                                
$prev $current_page 1;

                        if(
$current_page != $num_of_pages)
                                
$next $current_page 1;

                        
$min $current_page-5;
                        
$max $current_page+5;
                        if(
$min 1)
                                
$min 1;
                        if(
$current_page && $num_of_pages 10)
                                
$max $num_of_pages;
                        elseif(
$current_page && $current_page 10)
                                
$max 10;

                        if(
$max $num_of_pages)
                                
$max $num_of_pages;

                        if(
$prev != "")
                                
$pagination[] = "P-".$prev;

                        for(
$i=$min$i <= $max$i++)
                        {
                                
$pagination[] = $i;
                        }

                        if(
$next != "")
                                
$pagination[] = "N-".$next;
                        return 
$pagination;
        } 
With this function, you supply the current page number, and the total number of pages for the result set.

The function then returns an array which will be similar to this:

(If the current page is 2 and max pages = 5)
$pagination[0] = "P-1";
$pagination[1] = 1;
$pagination[2] = 2;
$pagination[3] = 3;
$pagination[4] = 4;
$pagination[5] = 5;
$pagination[6] = "N-3";

Usage example:
PHP Code:
$curr_page 2;
$total_pages 5;

$page pagination($curr_page$total_pages);
        foreach(
$pages as $page)
        {
                
//print $page;
                
if (stripos($page"p-") !== false)
                {
                        
$p substr($page, -1);
                        if(
$p != 1)
                         print 
"<a href='/".$p."/".urlencode($search)."'>Prev</a>";
                        else
                         print 
"<a href='/".urlencode($search)."'>Prev</a>";
                }
                elseif(
stripos($page"n-") !== false)
                {
                        
$p substr($page, -1);
                        print 
"<a href='/".$p."/".urlencode($search)."'>Next</a>";
                }
                else
                {
                  if(
$page != 1)
                        print 
"<a href='/".$page."/".urlencode($search)."'>".$page."</a>";
                  else
                        print 
"<a href='/".urlencode($search)."'>".$page."</a>";
                }
        } 
Note, i apologise for not using the standardised prefixes to variables with this example. I created it before i myself started using them.
__________________
Halo 3 Cheats
bluesaga is offline  
Reply With Quote
Old 11-01-2007, 04:38 PM   #8 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Default

thank you bluesaga.:)
meshi is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:02 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design