PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 9, 2022

[FIXED] SQL View not displaying all count results

 February 09, 2022     count, phpmyadmin, sql, view     No comments   

Issue

I've created a view in phpMyAdmin, and there is 37 results in the table that the view is of, but it's only showing 30 results in the count.

If I type a statement as follows

SELECT COUNT(*) FROM `vwk_activity` LIMIT 0,30

that displays that the count is 37 results, but if I try

SELECT COUNT(*) FROM `vwk_activity` LIMIT 30,30

it returns empty. If I type

SELECT COUNT(*) FROM `vwk_activity` LIMIT 50

That also returns 37.

This is an example of what I'm trying to do

// Set Page Limit
$page_limit = 30;
// Get Page Number
if (!isset($_GET['page']) ){$start=0;} else {$start = ($_GET['page'] - 1) * $page_limit;}
/* Check if Activity in DB */
try {
    $rs_check = $dbh->prepare("SELECT COUNT(*) FROM `vwk_activity` LIMIT ".$start.",".$page_limit);
    $rs_check->execute();
} catch (PDOException $e) {
    print "There was an error: " . $e->getMessage() . "<br/>";
    die();
}
$total = $rs_check->fetchColumn();

This works for plenty of my other pages, but it's not working on this one for some reason.


Solution

select count(*) returns the record count in a table back to you in a single row...not 1 row per record counted. If the count was 20 million, it would return 1 row with 20 million in it.

So this query is only returning 1 row. Limit 0,30 and limit 50 both return the first and only row saying 37. Limit 30,30 will return nothing in this case as it returns 30 rows from row 30 (which doesn't exist because this only returns one row)

Try select * from ... if you want to see 1 row for each record.



Answered By - Twelfth
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing