Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9108051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:43:03+00:00 2026-06-17T02:43:03+00:00

Hi stackoverflow readers and staff, I have a problem using a pagination code. All

  • 0

Hi stackoverflow readers and staff, I have a problem using a pagination code.
All is fine when I’m using SELECT COUNT(*) as num FROM $tbl_name, but when I try to SELECT COUNT(*) as num FROM $tbl_name WHERE marca=nokia, To paginate just results containing “nokia” word in line “marca” from an table named “modele” and I receive an error: “Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in E:\server\htdocs\pag.php on line 17”

This is the frame of code:

$marca = $_GET['marca'];
/* 
   First get total number of rows in data table. 
   If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE marca=$marca";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages1 = $total_pages['num'];

/* Setup vars for query. */
$targetpage = "paginare.php";   //your file name  (the name of this file)
$limit = 5;                                 //how many items to show per page
$page = $_GET['pagina'];
if($page) 
    $start = ($page - 1) * $limit;          //first item to display on this page
else
    $start = 0;                             //if no page var is given, set start to 0

/* Get data. */
$sql = "SELECT * FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql);
if ($page == 0) $page = 1;                  //if no page var is given, default to 1.
$prev = $page - 1;                          //previous page is page - 1
$next = $page + 1;                          //next page is page + 1
$lastpage = ceil($total_pages/$limit);      //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;                      //last page minus 1

/* 
    Now we apply our rules and draw the pagination object. 
    We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{   
    $pagination .= "<div class=\"pagination\">";
    //previous button
    if ($page > 1) 
        $pagination.= "<a href=\"$targetpage?page=$prev\">« Inapoi</a>";
    else
        $pagination.= "<span class=\"disabled\">« Inapoi</span>";   

    //pages 
    if ($lastpage < 7 + ($adjacents * 2))   //not enough pages to bother breaking it up
    {   
        for ($counter = 1; $counter <= $lastpage; $counter++)
        {
            if ($counter == $page)
                $pagination.= "<span class=\"current\">$counter</span>";
            else
                $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                 
        }
    }
    elseif($lastpage > 5 + ($adjacents * 2))    //enough pages to hide some
    {
        //close to beginning; only hide later pages
        if($page < 1 + ($adjacents * 2))        
        {
            for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<span class=\"current\">$counter</span>";
                else
                    $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                 
            }
            $pagination.= "...";
            $pagination.= "<a href=\"$targetpage?pagina=$lpm1\">$lpm1</a>";
            $pagination.= "<a href=\"$targetpage?pagina=$lastpage\">$lastpage</a>";     
        }
        //in middle; hide some front and some back
        elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
        {
            $pagination.= "<a href=\"$targetpage?pagina=1\">1</a>";
            $pagination.= "<a href=\"$targetpage?pagina=2\">2</a>";
            $pagination.= "...";
            for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<span class=\"current\">$counter</span>";
                else
                    $pagination.= "<a href=\"$targetpage?pagina=$counter\">$counter</a>";                   
            }
            $pagination.= "...";
            $pagination.= "<a href=\"$targetpage?pagina=$lpm1\">$lpm1</a>";
            $pagination.= "<a href=\"$targetpage?pagina=$lastpage\">$lastpage</a>";     
        }
        //close to end; only hide early pages
        else
        {
            $pagination.= "<a href=\"$targetpage?pagina=1\">1</a>";
            $pagination.= "<a href=\"$targetpage?pagina=2\">2</a>";
            $pagination.= "...";
            for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<span class=\"current\">$counter</span>";
                else
                    $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                 
            }
        }
    }

    //next button
    if ($page < $counter - 1) 
        $pagination.= "<a href=\"$targetpage?page=$next\">Inainte »</a>";
    else
        $pagination.= "<span class=\"disabled\">Inainte »</span>";
    $pagination.= "</div>\n";       
}

And here my php is ending, sorry for bad english and thank you in advance. Marcel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:43:04+00:00Added an answer on June 17, 2026 at 2:43 am

    Any string in SQL needs to be surrounded by ” or ‘.
    Like this:

    $query = "SELECT COUNT(*) as num FROM $tbl_name WHERE marca='{$marca}'";
    

    With the resulting query:

    SELECT COUNT(*) as num FROM $tbl_name WHERE marca='nokia'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working screenshot code that I got from here (stackoverflow). Problem is
stackoverflow forum member I am having some problem with a certain report designed using
Stackoverflow: For a cs assigment I am using the following code to stream audio.
using BouncyCastle and with help from a stackoverflow question I got this: using System.Net.Sockets;
I have a stackoverflow-style tag box, and it works fine except it won't submit
StackOverflow uses the GZip encoding on all of their pages; the same seems to
Hello stackoverflow people! I've got a problem which I haven't been able to solve
I'm seeing a lot of answers on StackOverflow that say that JavaScript executes code
Hello to all that read I am self learning C++ from a text book:
I was just viewing stackoverflow page source and I have a few simple questions;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.