Jump to content

Recommended Posts

i m using this php code for pagination navigation :

 

// output paging system (could also do it before we output the page content) 
    if ($page == 1) // this is the first page - there is no previous page 
        echo "Previous"; 
    else            // not the first page, link to the previous page 
        echo "<a href=\"index.php?page=" . ($page - 1) . "\" id=\"navigationURL\">Previous</a>"; 

    for ($i = 1; $i <= $pager->numPages; $i++) { 
        echo " | "; 
        if ($i == $pager->page) 
            echo "<span class=\"wp-pagenavi\">$i</span>" ; 
        else 
            echo "<a href=\"index.php?page=$i\" id=\"navigationURL\"> $i</a>"; 
    } 

    if ($page == $pager->numPages) // this is the last page - there is no next page 
        echo "Next"; 
    else            // not the last page, link to the next page 
        echo "   <a href=\"index.php?page=" . ($page + 1) . "\" id=\"navigationURL\">Next</a>"; 

 

but i want to display navigation like at the bottom of http://masalanews.net/

 

i tried css, but could not make it work.please anyone can help me out in this.

Link to comment
https://forums.phpfreaks.com/topic/145186-navigation-and-pagination/
Share on other sites

This is the whole script :

 

<?php

if (!ini_get("register_globals")) {
    import_request_variables('GPC');
}
//E?C?? ??I C?E? CEO E?
$phpver = phpversion();
if ($phpver < '4.1.0') {
    $_GET = $HTTP_GET_VARS;
    $_POST = $HTTP_POST_VARS;
    $_SERVER = $HTTP_SERVER_VARS;
}
$phpver = explode(".", $phpver);
$phpver = "$phpver[0]$phpver[1]";
if ($phpver >= 41) {
    $PHP_SELF = $_SERVER['PHP_SELF'];
} 








class Pager 
   { 
       function getPagerData($numHits, $limit, $page) 
       { 
           $numHits  = (int) $numHits; 
           $limit    = max((int) $limit, 1); 
           $page     = (int) $page; 
           $numPages = ceil($numHits / $limit); 

           $page = max($page, 1); 
           $page = min($page, $numPages); 

           $offset = ($page - 1) * $limit; 

           $ret = new stdClass; 

           $ret->offset   = $offset; 
           $ret->limit    = $limit; 
           $ret->numPages = $numPages; 
           $ret->page     = $page; 

           return $ret; 
       } 
   }  



    // get the pager input values 
    $page = $_GET['page']; 
    $limit = 16; 
    $result = mysql_query("select count(*) from ratings"); 
    $total = mysql_result($result, 0, 0); 

    // work out the pager values 
    $pager  = Pager::getPagerData($total, $limit, $page); 
    $offset = $pager->offset; 
    $limit  = $pager->limit; 
    $page   = $pager->page; 

    // use pager values to fetch data 
    $query = "select * from ratings order by id DESC limit $offset, $limit"; 
    $result = mysql_query($query); 

    // use $result here to output page content 


//my addition

//grab all the content

   //Custom Table Stsrt//
        $cols = 4; //number of coloms
        $i =1;
        echo "<table border=\"1\" cellpadding=\"4\" cellspacing=\"4\" width=\"95%\" id=\"table1\" bordercolor=\"#ffffff\" bgcolor=\"#ffffff\" style=\"border-collapse: collapse; border-style: double; border-width: 1\">"
             ."<tr>";

while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
   $id=$r["id"];
   $name=$r["name"];
   $image=$r["image"];
   
   
   
   //display the row
   
   
   
   $mybox = "
   <br>
   <a href='view.php?id=$id'><img src='http://wallpapersfreak.com/freaky/1600x1200/images/sml120_$image' width =\"120\" height =\"90\" style=\"border: 2px double #824149;\"></a>

   <br>
   <a href='view.php?id=$id'>$name</a>
   <br>";
   


                if (is_int($i / $cols)){
                    echo "<td width='150' align='center'>$mybox</td></tr><tr>";
                }else{
                    echo "<td width='150' align='center'>$mybox</td>";
                }
             $i++;
          //end if
       }//end while
       echo "</tr></table>";
       //Custom Table End//
   


//ends my addition



    // output paging system (could also do it before we output the page content) 
    if ($page == 1) // this is the first page - there is no previous page 
        echo "Previous"; 
    else            // not the first page, link to the previous page 
        echo "<a href=\"index.php?page=" . ($page - 1) . "\" id=\"navigationURL\">Previous</a>"; 

    for ($i = 1; $i <= $pager->numPages; $i++) { 
        echo " | "; 
        if ($i == $pager->page) 
            echo "<span class=\"wp-pagenavi\">$i</span>" ; 
        else 
            echo "<a href=\"index.php?page=$i\" id=\"navigationURL\"> $i</a>"; 
    } 

    if ($page == $pager->numPages) // this is the last page - there is no next page 
        echo "Next"; 
    else            // not the last page, link to the next page 
        echo "   <a href=\"index.php?page=" . ($page + 1) . "\" id=\"navigationURL\">Next</a>"; 
?> 

Here you go... hopefully you can understand how to use it

 


<?php

function makePagination ( $items_total, $items_per_page, $items_start, $items_variable, $items_maximum, $items_update, $items_text, $items_url )
{
$links = array ( 'pages' => array (), 'first' => '', 'last' => '', 'previous' => '', 'next' => '', 'total' => '' );

$items_pages = ceil ( $items_total / $items_per_page );

if ( $items_pages > 1 )
{
	/* page we are on */

	$on = floor ( ( $items_start - 1 ) / $items_per_page ) + 1;

	/* make page links if it's allowed */

	if ( $items_maximum > 0 )
	{	
		for ( $x = 1; $x <= $items_pages; $x++ )
		{
			$links['pages'][$x] = sprintf ( '<a href="%s%s=%d" title="%s">%s</a>', $items_url, $items_variable, ( ( ( $x - 1 ) * $items_per_page ) + 1 ), $items_text['go_to_title'] . $x, $items_text['go_to_anchor'] . $x );
		}

		/* limit the number of page links to show */

		if ( $items_pages > $items_maximum )
		{
			$links['pages'] = array_slice ( $links['pages'], max ( 0, $on - $items_update ), $items_maximum );
		}

		/* make the previous page link */

		if ( $on > 1 )
		{
			$links['previous'] = sprintf ( '<a href="%s%s=%d" title="%s">%s</a>', $items_url, $items_variable, ( ( ( $on - 2 ) * $items_per_page ) + 1 ), $items_text['go_previous_title'], $items_text['go_previous_anchor'] );
		}

		/* make the next page link */

		if ( $on < $items_pages )
		{
			$links['next'] = sprintf ( '<a href="%s%s=%d" title="%s">%s</a>', $items_url, $items_variable, ( ( $on * $items_per_page ) + 1 ), $items_text['go_next_title'], $items_text['go_next_anchor'] );
		}
	}
	else
	{
		/* only next & previous links allowed */

		/* make the previous page link */

		if ( $items_start > 1 && $items_total > 0 )
		{
			$links['previous'] = sprintf ( '<a href="%s%s=%d" title="%s">%s</a>', $items_url, $items_variable, max ( $items_start - $items_per_page, 1 ), $items_text['go_previous_title'], $items_text['go_previous_anchor'] );
		}

		/* make the next page link */

		if ( min ( $items_start + $items_per_page - 1, $items_total ) < $items_total )
		{
			$links['next'] = sprintf ( '<a href="%s%s=%d" title="%s">%s</a>', $items_url, $items_variable, ( $items_start + $items_per_page ), $items_text['go_next_title'], $items_text['go_next_anchor'] );
		}
	}

	/* on page of total pages */

	$links['total'] = sprintf ( $items_text['go_total_pages'], $on, $items_pages );

	/* go to the first page */

	if ( $on > 1 )
	{
		$links['first'] = sprintf ( '<a href="%s%s=%d" title="%s">%s</a>', $items_url, $items_variable, 1, $items_text['go_first_title'], $items_text['go_first_anchor'] );
	}

	/* go to the last page */

	if ( $items_pages != $on )
	{
		$links['last'] = sprintf ( '<a href="%s%s=%d" title="%s">%s</a>', $items_url, $items_variable, ( ( ( $items_pages - 1 ) * $items_per_page ) + 1 ), $items_text['go_last_title'], $items_text['go_last_anchor'] );
	}
}

return $links;
}

/* $items_total */

/*
* this is total number items returned from...
* $result = mysql_query ( "SELECT COUNT(*) AS items_total FROM table;" );
* $found = mysql_fetch_assoc ( $result );
* $items_total = $found['items_total'];
*/

$items_total = 143;



/* $items_per_page */

/*
* this is the total number of items you plan of showing PER PAGE.
* The pagination system needs to know this in order to create it's
* links!
*/

$items_per_page = 10;



/* $items_url */

/*
* this is the url to the page that you are needing pagination
* on. Exampe...
* http://site.com/service.php?a=1&b=2&
* If you need to attach other query_string variables be sure the
* URL ends with * & *. If you're not attaching other query_string
* variables then the URL must end with * ? *
*/

$items_url = 'http://localhost/test.php?';



/* $items_variable */

/*
* this is the pagination variable that is included in the URL that
* that tells the pagination system where to begin or continue it's
* next pagination action. Example (items_variable) equals * page *
* http://site.com/service.php?page=items_start
*/

$items_variable = 'page';



/* $items_start */

/*
* this will come from the URL items_variable in this example we call
* * page * if it is set. If it is not set we assign it a value of * 1 *
*/

/* always validate items_variable (this is not enough validation, its an example only) */

$items_start = isset ( $_GET['page'] ) ? $_GET['page'] : 1;



/* $items_maximum */

/*
* this is the maximum number of links to show on each page. Say you
* have (50) pages and you only want to show (10) links as a time. this
* will allow you to do that. Set to * 0 * to only allow prev & next links!
*/

$items_maximum = 5;



/* $items_update */

/*
* this is used with $items_maximum. This variable tells the pagination system
* when to advance the page link counter. If you want to advance the link counter
* for every page use the value * 1 *. But really this value should be created by
* using floor ( ( $items_maximum / 2 ) + 1 ); but I didn't do that. This value must
* be less than $items_maximum. if $items_maximum equals 0 this value is not used!
*/

$items_update = 3;

/* $items_text */

/*
* this is the language variables and template array. It is used by the pagination system
* to insert language specific variables into the links and to also format the display!
*/

$items_text = array (
'go_next_title'       => 'Next Page', 
'go_next_anchor'      => '»', 
'go_previous_title'   => 'Previous Page', 
'go_previous_anchor'  => '«', 
'go_to_title'         => 'Go to page: ', 
'go_to_anchor'        => '', 
'go_last_title'       => 'Go to the last page', 
'go_last_anchor'      => 'Last »', 
'go_first_title'      => 'Go to the first page', 
'go_first_anchor'     => 'First «', 
'go_total_pages'      => '%d of %d Pages'
);

/* now lets run it */

$data = makePagination ( $items_total, $items_per_page, $items_start, $items_variable, $items_maximum, $items_update, $items_text, $items_url );

/* now lets echo our navigation result */

echo '<div id="navigation">';
echo '	<div class="wp-pagenavi">';
echo '		<span class="pages">' . $data['total'] . '</span>';

/* if you don't want to include something remove the (if(){}) */

if ( ! empty ( $data['first'] ) )
{
echo '<span>' . $data['first'] . '</span>';
}

/* don't include previous
if ( ! empty ( $data['previous'] ) )
{
echo '<span>' . $data['previous'] . '</span>';
}
*/

if ( ! empty ( $data['pages'] ) )
{
echo '<span>' . implode ( '', $data['pages'] ) . '</span>';
}

/* don't include next
if ( ! empty ( $data['next'] ) )
{
echo '<span>' . $data['next'] . '</span>';
}
*/

if ( ! empty ( $data['last'] ) )
{
echo '<span>' . $data['last'] . '</span>';
}

echo '	</div>';
echo '</div>';

?>

Dear see this file at here :

 

http://wallpapersfreak.com/freaky/index2.php

 

it messed up whole web site deisgn. and the center is what i want in this format.

 

http://wallpapersfreak.com/freaky/index.php

 

 

please help

thanks

Download fixes...

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.