Man kan ordna så den slipper göra en fråga för varje tabell genom att gå igenom $tables och bygga upp en JOIN (inte vad jag gör nedan).
Kod:
$postcount = 0;
$tables = array();
$sql = mysql_query("SHOW TABLE STATUS FROM wordpress")or die(mysql_error());
while ($r = mysql_fetch_row($sql))
{
if (preg_match("/wp_([0-9]+)_post/", $r[0], $match))
{
$tables[] = $match[1];
}
}
foreach ($tables as $key => $id)
{
$query = sprintf("SELECT COUNT(*) FROM wp_%u_post", $id);
$sql = mysql_query($query)or die(mysql_error());
$postcount += mysql_result($sql, 0);
}
echo "Totalt: ", $postcount;