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

Recommended Answers

All 3 Replies

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.

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?

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

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.