Suchy Posted January 13, 2008 Share Posted January 13, 2008 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/85867-paging-problem/ Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 Your $filter variable isn't being set outside the if/elseif statement. Quote Link to comment https://forums.phpfreaks.com/topic/85867-paging-problem/#findComment-438314 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.