$query_Recordset4 = sprintf("SELECT TABLE_NAME FROM information_schema.TABLES
WHERE TABLE_SCHEMA='message' and TABLE_NAME like '1a%nd5'");
$Recordset4 = mysql_query($query_Recordset4, $messageconnection);
$totalRows_Recordset4 = mysql_num_rows($Recordset4);
I ran SQL query about SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='message' and TABLE_NAME like '1a%nd5'
in PhpMyAdmin. It revealed "2" total rows.
However, I queried the answer "mysql_num_rows" in php was "0". Doesn't "mysql_num_rows" work in SELECT TABLE_NAME FROM information_schema.TABLES
? What is the alternative method?
If a alternative method is below content. $query_Recordset5 = sprintf("SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA='message' and TABLE_NAME like '$colname_Recordset6' "); $row_Recordset5 = mysql_fetch_assoc($Recordset5);
The result of "mysql_fetch_assoc" revealed nothing, but it worked in other mysql_query. How can I solve this problem?
Your problem is actually in your call to sprintf
, it is trying to process %n
as a conversion specification. You need to change the %
in that string to %%
i.e.
$query_Recordset4 = sprintf("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='message' and TABLE_NAME like '1a%%nd5'");
You should also switch from using mysql_
functions to mysqli_
as the mysql functions have been deprecated as of PHP5.5 and removed as of PHP7 due to bugs in the code.
Method mysql_num_rows is good to count result after select from some table(see doc http://php.net/manual/en/function.mysql-num-rows.php).
Just do select on your table with count: https://dev.mysql.com/doc/refman/8.0/en/counting-rows.html
Total rows in PhpMyAdmin? You can't do this in one query way. It sounds, you try doing something wrong. Total rows is good to count on one specific table. You can also loop through all tables in database to get all records but I don't think you really need this(I have never heard of something like that).
BTW. use mysqli instead of mysql
print_r(mysql_fetch_array($Recordset4));
// UPDATE
$query = mysqli_query($messageconnection, "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='message' and TABLE_NAME like '1a%%nd5'");
$row = mysqli_fetch_assoc($query);
$result_count = $row['COUNT(*)'];
echo $result_count;