Jump to content

Paging problem


Suchy

Recommended Posts

I am having problem with a paging system on my site, especialy the if/else statement:

 

<?php
if(in("selected")) // someone selected a type from dropdown menu
{

$selected_id = $_POST['selected_id'];
$query = "SELECT * FROM news WHERE type LIKE '%$selected_id%' ORDER BY id DESC LIMIT $offset, $rowsPerPage" ; 
$result = mysql_query($query);
$dbResults = getRows($result);

// how many rows we have in database
$query   = "SELECT COUNT(*) AS numrows FROM news WHERE type LIKE '%$selected_id%' ";
$result  = mysql_query($query) ;
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$filter = 1;		
}
elseif ($filter == 1) // someone selected type from dropdown, and went to second page (additional 20 results)
{
$selected_id = $_POST['selected_id'];
$query = "SELECT * FROM news WHERE type LIKE '%$selected_id%' ORDER BY id DESC LIMIT $offset, $rowsPerPage" ; 
$result = mysql_query($query);
$dbResults = getRows($result);

// how many rows we have in database
$query   = "SELECT COUNT(*) AS numrows FROM news WHERE type LIKE '%$selected_id%' ";
$result  = mysql_query($query) ;
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$filter = 1;	
}
else // no selection made, show all news from db
{
$query = "SELECT * FROM news ORDER BY id DESC LIMIT $offset, $rowsPerPage";
$result = mysql_query($query);
$dbResults = getRows($result);

// how many rows we have in database
$query   = "SELECT COUNT(*) AS numrows FROM news";
$result  = mysql_query($query) ;
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$filter = 0;
}

?>

 

The way it supposed to work is that all news are shown ( else case) unles ssomeone selects a type form dropdown menu (ex. sports, local.....).

The selection menu (if case) works only on first page (first 20 results) but when I go onto the 2nd page insted of the elseif case ($filter == 1) being used the else case is used, thus insted of 20 results of the filtered news being shown on 2nd page, the 20 news from all types are displayed.

 

How can I fix this bug ?

Link to comment
https://forums.phpfreaks.com/topic/85867-paging-problem/
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.