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 8768951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:12:09+00:00 2026-06-13T17:12:09+00:00

I’m working on pagination on a website I’m building and I found a good

  • 0

I’m working on pagination on a website I’m building and I found a good pagination example here: http://www.awcore.com/dev/1/3/Create-Awesome-PHPMYSQL-Pagination_en . I’d like to us this on my page but am using mysqli instead of mysql and need to convert some of it.

I’m new to MySQL and am trying to figure out the syntax to converting the following code:

function pagination($query, $per_page = 10,$page = 1, $url = '?'){        
    $query = "SELECT COUNT(*) as `num` FROM {$query}";
    $row = mysql_fetch_array(mysql_query($query));
    $total = $row['num'];
    $adjacents = "2"; 

I know it doesn’t give you much as to what the entire code is (it’s about 100 lines long) but I’m assuming this may be an easy syntax change. I had initially done it likes this:

function pagination($query, $per_page = 10,$page = 1, $url = '?'){        
    $query = "SELECT COUNT(*) as `num` FROM {$query}";
    $row = mysqli_fetch_array(mysqli_query($query));
    $total = $row['num'];
    $adjacents = "2";

I am aware that mysqli_query needs to take two parameters but I was also under the impression that it was the same for mysql_query so I guess I’m just not understanding the code. Sorry if this is a super basic question, I’m just trying to wrap my head around some of these concepts! Thanks for any help.

BTW I did see this question (Converting from mysql to mysqli (mysql_fetch_array)) but it seemed like he was taking several extra steps that may not need to be taken.

EDIT

Here’s the error messages I’m getting with the above code FYI:

Warning: mysqli_query() expects at least 2 parameters, 1 given in linkinformation/functions.php on line 9

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in linkinformation/functions.php on line 9

EDIT

So I added a connection within the function (is that the right approach? I tried connecting outside the function but it was grabbing the info):

function pagination($mysqli, $query, $per_page = 10,$page = 1, $url = '?'){        
    $mysqli = mysqli_connect("localhost","username","password", "db_name");
    $query = "SELECT COUNT(*) as `num` FROM {$query}";
    $row = mysqli_fetch_array(mysqli_query($mysqli, $query));
    $total = $row['num'];
    $adjacents = "2"; 

I get this warning:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in linkstuff/functions.php on line 10

It’s getting a boolean (which I’m assuming is TRUE) whereas it should be getting something else I suppose/the actual query.

  • 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-13T17:12:11+00:00Added an answer on June 13, 2026 at 5:12 pm

    You need to change your connection to mysqli as well, and pass the connection object to mysqli_query as the first argument.

    function pagination($link, $query, $per_page = 10,$page = 1, $url = '?'){        
        $query = "SELECT COUNT(*) as `num` FROM {$query}";
        $row = mysqli_fetch_array(mysqli_query($link, $query));
        $total = $row['num'];
        $adjacents = "2";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
i got an object with contents of html markup in it, for example: string

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.