Tag Archives: PHP total number of rows

PHP: How to get the total number of data in the MySQL table (total number of rows)

RewCount (): Returns the number of rows affected:

 $sql='select * from '.$_POST['fname'].'_blog_data';
		 $sth=$pdo->query($sql);
		 die('<script>alert('.$sth->rowCount().')</script>');

2

$q = $pdo->query("SELECT count(*) from w_login_record;"); $rows = $q->fetch(); $rowCount = $rows[0];
		 die('alter("'.$rowCount.'")');

3

Use the fetchAll function $q = $db->query("SELECT ..."); $rows = $q->fetchAll(); $rowCount = count($rows);