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

  • Home
  • SEARCH
  • 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 122007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:03:38+00:00 2026-05-11T04:03:38+00:00

I am having trouble with modifying a php application to have pagination. My error

  • 0

I am having trouble with modifying a php application to have pagination. My error seems to be with my logic, and I am not clear exactly what I am doing incorrectly. I have had before, but am not currently getting errors that mysql_num_rows() not valid result resource and that invalid arguments were supplied to foreach. I think there is a problem in my logic which is stopping the results from mysql from being returned.

All my ‘test’ echos are output except testing while loop. A page is generated with the name of the query and the word auctions, and first and previous links, but not the next and last links. I would be grateful if a more efficient way of generating links for the rows in my table could be pointed out, instead of making a link per cell. Is it possible to have a continuous link for several items?

<?php if (isset($_GET['cmd']))   $cmd = $_GET['cmd']; else die('You should have a 'cmd' parameter in your URL'); $query =''; if (isset($_GET['query'])) {     $query = $_GET['query']; } if (isset($_GET['pg'])) {   $pg = $_GET['pg'];  }   else $pg = 1; $con = mysql_connect('localhost','user','password'); echo 'test connection<p>'; if(!$con) {     die('Connection failed because of' .mysql_error()); } mysql_query('SET NAMES utf8'); mysql_select_db('database',$con); if($cmd=='GetRecordSet'){     echo 'test in loop<p>';      $table = 'SaleS';     $page_rows = 10;     $max = 'limit ' .($pg - 1) * $page_rows .',' .$page_rows;     $rows = getRowsByProductSearch($query, $table, $max);     echo 'test after query<p>';     $numRows = mysql_num_rows($rows);     $last = ceil($rows/$page_rows);     if ($pg < 1) {         $pg = 1;     } elseif ($pg > $last) {         $pg = $last;     }     echo 'html stuff <p>';      foreach ($rows as $row) {  echo 'test foreach <p>';         $pk = $row['Product_NO'];         echo '<tr>' . '\n';         echo '<td><a href='#' onclick='updateByPk(\'Layer2\', \'' . $pk . '\')'>'.$row['USERNAME'].'</a></td>' . '\n';         echo '<td><a href='#' onclick='updateByPk(\'Layer2\', \'' . $pk . '\')'>'.$row['shortDate'].'</a></td>' . '\n';         echo '<td><a href='#' onclick='updateByPk(\'Layer2\', \'' . $pk . '\')'>'.$row['Product_NAME'].'</a></td>' . '\n';         echo '</tr>' . '\n';     }     if ($pg == 1) {     } else {         echo ' <a href='{$_SERVER['PHP_SELF']}?pg=1'> <<-First</a> ';         echo ' ';         $previous = $pg-1;         echo ' <a href='{$_SERVER['PHP_SELF']}?pg=$previous'> <-Previous</a> ';     }     echo '---------------------------';     if ($pg == $last) {     } else {         $next = $pg+1;         echo ' <a href='{$_SERVER['PHP_SELF']}?pg=$next'>Next -></a> ';         echo ' ';         echo ' <a href='{$_SERVER['PHP_SELF']}?pg=$last'>Last ->></a> ';     }     echo '</table>\n'; } echo '</div>'; function getRowsByProductSearch($searchString, $table, $max) {     $searchString = mysql_real_escape_string($searchString);     $result = mysql_query('SELECT Product_NO, USERNAME, ACCESSSTARTS, Product_NAME, date_format(mycolumn, '%d %m %Y') as shortDate FROM {$table} WHERE upper(Product_NAME) LIKE '%' . $searchString . '%'' . $max);     if($result === false) {         echo mysql_error();     }     $rows = array();     while($row = mysql_fetch_assoc($result)) {         echo 'test while <p>';         $rows[] = $row;     }     return $rows;     mysql_free_result($result); } 

edit: I have printed out the mysql error of which there was none. However 8 ‘test whiles’ are printed out, from a database with over 100 records. The foreach loop is never entereded, and I am unsure why.

  • 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. 2026-05-11T04:03:38+00:00Added an answer on May 11, 2026 at 4:03 am

    The problem (or at least one of them) is in the code that reads:

    $rows = getRowsByProductSearch($query, $table, $max); $numRows = mysql_num_rows($rows); 

    The $numRows variable is not a MySQL resultset, it is just a normal array returned by getRowsByProductSearch.

    Change the code to read:

    $rows = getRowsByProductSearch($query, $table, $max); $numRows = count($rows); 

    Then it should at least find some results for you.

    Good luck, James

    Hi there,

    The next problem is with the line that reads:

    $last = ceil($rows/$page_rows); 

    It should be changed to read:

    $last = ceil($numRows / $page_rows); 

    Would recommend adding the following lines to the start of you script at least while debugging:

    ini_set('error_reporting', E_ALL | E_STRICT); ini_set('display_errors', 'On'); 

    As that would have thrown up a fatal error and saved you a whole lot of time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 139k
  • Answers 139k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's a list of the recommended tags in Visual Studio,… May 12, 2026 at 7:43 am
  • Editorial Team
    Editorial Team added an answer from the command line: sudo tlmgr update --all tlmgr is… May 12, 2026 at 7:43 am
  • Editorial Team
    Editorial Team added an answer Your LINKS table looks like many-to-many mapping table between LOCATION… May 12, 2026 at 7:43 am

Related Questions

I am building an application plugin in Python which allows users to arbitrarily extend
We Want to Run Our C# Code on the JVM My company has a
I am having trouble with IE7. I have a header, which is an IMG.
I am having trouble with my Visual Studio 2005 IntelliSense for some time now.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.