0

I need to get the name of the table with the biggest number of rows, I can find the biggest number of rows with function count and than function max, but i don't know how to see from which table is that maximum, can anyone help? tnx

2
Contributors
3
Replies
26
Views
4 Years
Discussion Span
Last Post by Tpojka
0

If it is mysql driven application, there is mysql_list_tables() function.
When you check all table names and collect it with loop (probably should unset information_schema, mysql and performance_schema) you can use comparation part of code to check which table has more rows.

0

Hm, I am not sure that I get it, can you maybe write me a code because this function is not helping me so much?

0

Sorry, I mixed up DBs and tables a bit.

Anyway, first example on link I left:

<?php
$dbname = 'mysql_dbname';

if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
    echo 'Could not connect to mysql';
    exit;
}

$sql = "SHOW TABLES FROM $dbname"; //SHOW TABLES is sql function you need
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}
$tables = array();
while ($row = mysql_fetch_row($result)) {
    $tables[] = $row[0];
}

mysql_free_result($result);

// echo '<pre>', print_r($tables), '</pre>'; 

$counted_tables_values = array();

foreach ($tables as $table)
{
    // make your counting, store it in new array 
}

// here you make comparation of values or find max in given array

?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.