Jump to content

Recommended Posts

You can use "SHOW TABLES LIKE 'windows_%' to retrieve the tables and then create a query that looks similar to the following

MYSQL 4.1 or higher
[code]
SELECT (SELECT COUNT(*) FROM table1) + (SELECT COUNT(*) FROM table2) AS total
[/code]

Post the version of MYSQL you're using (SELECT VERSION()) and the code you've written if you have any problems.
This should also give you what you're after, and maybe slightly easier than what Shoz posted, but it does involve more queries.

[code]<?php
// This will give you a list of tables
$sql = "SHOW TABLES LIKE 'windows_%'";
$result = mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error());
while ($table = mysql_fetch_array($result, MYSQL_NUM)){
  $tables[] = $table[0]; // Put each table into an array
}

// Loop through the tables getting the totals for each
foreach ($tables as $t){
  $sql = "SELECT COUNT(*) FROM $t";
  $result = mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error());
  $total += mysql_result($result, 0); // add the count to the running total
}

// Echo the total posts
echo $total;
?>[/code]

Regards
Huggie
[quote author=HuggieBear link=topic=124416.msg515447#msg515447 date=1170001020]
Shoz,

That will work so long as the table type is that of MyISAM or ISAM.  If it's InnoDB then it will only be an estimated row count.

Regards
Huggie
[/quote]

You're right. Good call.
[quote author=boo_lolly link=topic=124416.msg515491#msg515491 date=1170006562]
[url=http://php.net/mysql_num_rows]mysql_num_rows()[/url]???
[/quote]

Boo, that's not really appropriate in this situation.

Regards
Huggie
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.