Jump to content

[SOLVED] php next prev


sheriff

Recommended Posts

hi all ...

 

I have tryed to adapt a php navigation to my page.

it's almost ok, but I have a little problem.

 

it shows me the first page ok, but when I click next,

the page is empthy.

I don't know why.

 

Maybe someone can help me ! :)

 

this is the code:

 

<?php
            
            // how many rows to show per page
            $rowsPerPage = 20;
            
            // by default we show first page
            $pageNum = 1;
            
            // if $_GET['page'] defined, use it as page number
            if(isset($_GET['page']))
            {
                $pageNum = $_GET['page'];
            }
            
            // counting the offset
            $offset = ($pageNum - 1) * $rowsPerPage;

		// remove white spaces befor and after the word
            // $trimmed = trim($_REQUEST['search']);

		$query  = "[b]SELECT * FROM products WHERE pr_type='$_REQUEST[id]' LIMIT $offset, $rowsPerPage[/b]";
            $result = mysql_query($query) or die("Query failed: $query<br /><br />mysql_error()");
            
		$row_count = "1";
            
            $color1 = "#DDDDDD"; 
            $color2 = "#CCCCCC"; 
            
            
            // print the random numbers
            while($val = mysql_fetch_array($result))
            { 
                $row_color = ($row_count % 2) ? $color1 : $color2;
            
            ?>	
<tr>
    	<td bgcolor="<?php echo $row_color; ?>" align="center" width="30"><span class="cn_text"><?php echo $val['pr_id']; ?></span></td>
        <td width="150" bgcolor="<?php echo $row_color; ?>"><span class="cn_text"> <?php echo $val['pr_name']; ?></span></td>
        <td width="200" bgcolor="<?php echo $row_color; ?>"><span class="cn_text"> <?php echo $val['pr_desc']; ?></span></td>
        <td align="center" bgcolor="<?php echo $row_color; ?>"><span class="cn_text"><?php echo $val['pr_price']; ?> RON</span></td>
    </tr>
    
<?php
            //echo "$val <br>";
            //echo $id = $val['pr_id'];

		$row_count++;
            }

		?>
            
</table><br>

            <?php

            // how many rows we have in database
            $query   = "[b]SELECT COUNT(*) AS numrows FROM products WHERE pr_type='$_REQUEST[id]'[/b]";
            $result  = mysql_query($query) or die('Error, query failed');
            $row     = mysql_fetch_array($result, MYSQL_ASSOC);
            $numrows = $row['numrows'];
            
            // how many pages we have when using paging?
            $maxPage = ceil($numrows/$rowsPerPage);
            
            $self = $_SERVER['PHP_SELF'];
            
            // creating 'previous' and 'next' link
            // plus 'first page' and 'last page' link
            
            // print 'previous' link only if we're not
            // on page one
            if ($pageNum > 1)
            {
                $page = $pageNum - 1;
                $prev = " [<a href=\"$self?page=$page\"><span class=\"cnb_text\">Inapoi</span></a>] ";
                
                $first = " [<a href=\"$self?page=1\"><span class=\"cnb_text\">Prima pagina</span></a>] ";
            } 
            else
            {
                $prev  = ' [<span class=\"cn_text\">Inapoi</span>] ';       // we're on page one, don't enable 'previous' link
                $first = ' [<span class=\"cn_text\">Prima Pagina</span>] '; // nor 'first page' link
            }
            
            // print 'next' link only if we're not
            // on the last page
            if ($pageNum < $maxPage)
            {
                $page = $pageNum + 1;
                $next = " [<a href=\"$self?page=$page\"><span class=\"cnb_text\">Inainte</span></a>] ";
                
                $last = " [<a href=\"$self?page=$maxPage\"><span class=\"cnb_text\">Ultima Pagina</span></a>] ";
            } 
            else
            {
                $next = ' [<span class=\"cn_text\">Inainte</span>] ';      // we're on the last page, don't enable 'next' link
                $last = ' [<span class=\"cn_text\">Ultima Pagia</span>] '; // nor 'last page' link
            }
            
            // print the page navigation link
            echo "<span class=\"cn_text\">" . $first . $prev . " Pagina <strong>$pageNum</strong> din <strong>$maxPage</strong> " . $next . $last . "</span>";
            
            ?>

 

This is the page.

 

http://cristi.prosportequipment.ro/prosportnew/produse.php?id=1

 

Thanks in advice.

Link to comment
https://forums.phpfreaks.com/topic/64642-solved-php-next-prev/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.