Hi, i made this pagination system in the news list, but it's repeating the first data in every pages.

So when i say i want 2 nes per page it's giving me 3 instead, because of it...

if(isset($_GET['page'])){
                            require('config.php');
                            $page = $_GET["page"]; //Getting Page number

                            $pages_query = mysql_query("SELECT COUNT(IdNoticia) FROM noticias"); // Counting total rows

                            if($page=="" || $page=="0" || $page>$pages_query) { //checking is p is set and greater than 0
                                $page = 1; //if not set than setting it to 1
                            }

                            $per_page = 2; //Total data to display per page
                            $pages = ceil(mysql_result($pages_query, 0) / $per_page); //dividing total rows with total data to


                            $start = ($page - 2) * $per_page; // subtracting $p value with 1 and multiplying it with $per_page for                  example 2-1=1*10 = 10

                            $QuerySelectAllNews = mysql_query("SELECT * FROM noticias ORDER BY IdNoticia ASC LIMIT $start, $per_page");      
                            $SelectAllNews = mysql_fetch_array($QuerySelectAllNews);
                            //Running our query

                            $content='';
                            do{
                                $content.='<div id="square_news">';
                                    $content.='<div id="news_banner">';
                                        $content.='<img src="'.$SelectAllNews['ImagemNoticia'].'" />';
                                    $content.='</div>';

                                    $content.='<h2 class="square_news_title">';
                                        $content.='<a href="?idnews='.$SelectAllNews['IdNoticia'].'">'.$SelectAllNews['TituloNoticia'].'</a>';
                                        $content.='<div class="social">';
                                            $content.='<a href="#"><img src="http://bass.house.gov/sites/karenbass.house.gov/files/images/facebook_0.png" width="70px" /></a>';
                                        $content.='</div>';
                                        $content.='<span class="line"></span>';
                                    $content.='</h2>'
                                $content.='</div>';

                                echo $content;
                            }while($SelectAllNews = mysql_fetch_array($QuerySelectAllNews));

                            for($a=1;$a<=$pages;$a++) { //using for to display number
                                echo "<a href='?page=$a' class='page_link'>$a</a> "; //printing numbers also using link tags
                            }
                        }

Two things I noticed, on line 7 you're calling $pages_query which is a result set that hasn't been fetched. Should be mysql_result($pages_query, 0) but that's not what's causing your issue. On line 15 you're subtracting 2 from $page vice 1 which is setting your start too far back.

$start = ($page - 1) * $per_page;

It didn't do any change, i keep having the first data repeating in every page.

I'm guessing your if statement is evaluating to true and is setting page to 1. What do you get when you echo your start variable after you do your math?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.