Jump to content

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

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.