Adding to selection?
I have the following code:
$sql="SHOW DATABASES WHERE `Database` NOT LIKE '%backup%' AND `Database` NOT LIKE 'mysql' AND `Database` NOT LIKE '%schema%'";
$query=mysql_query($sql,$connect);
while ($row = mysql_fetch_assoc($query)) {
$sql1="SHOW TABLES FROM `".$row['Database']."`";
$query1=mysql_query($sql1, $connect);
while( $row2 = mysql_fetch_assoc($query1) ) {
$row2=implode(" ",$row2);
$sql1="SELECT COUNT(*) FROM `".$row['Database']."`.`".$row2."`";
$query1=mysql_query($sql1,$connect);
echo implode(" ",mysql_fetch_assoc($query1)).'<br>';
}
}
I have two databases and two tables with two records The above code counts each record of each table from each database and displays two arrays corresponding to the number of records of each table.
So it will output:
2 2
I need to sum them, so the result is 4. Help please?
+3
user4049854
source
to share
1 answer
Just recalculate the amount in PHP:
$sql="SHOW DATABASES WHERE `Database` NOT LIKE '%backup%' AND `Database` NOT LIKE 'mysql' AND `Database` NOT LIKE '%schema%'";
$query=mysql_query($sql,$connect);
$total = 0;
while ($row = mysql_fetch_assoc($query)) {
$sql1="SHOW TABLES FROM `".$row['Database']."`";
$query1=mysql_query($sql1, $connect);
while($row2 = mysql_fetch_assoc($query1) ) {
$row2=reset($row2);
$sql2="SELECT COUNT(*) FROM `".$row['Database']."`.`".$row2."`";
$query2=mysql_query($sql2,$connect);
$total += mysql_result($query2, 0);
}
}
echo $total;
And also stop using mysql _ * functions , they are deprecated ...
+1
source to share