Matpatnik 1 Posted May 27, 2007 Report Share Posted May 27, 2007 Hi guys,In my database I have 26 table that are identify by a word and a letter like that: mots_a, mots_b, mots_c...is it possible to do something to increase the letter so I will only have to call them like this: $table = "mots_" . $letter;What I'm trying to do is counting every single row in my 26 tables to get the total word in my database. I will probably have to split some table later on like this: mots_aa, mots_ab, mots_ac, mots_ad... So I will have maximum 676 tables in the future but it have to count only the table starting by "mots_"Can someone help my with that please, I have no idea where to start (well I do have a little idea but it will be way too long. it was to call every table individually, get the mysql_num_rows, store every number then addition all the number for a great total)Thank you for your help Quote Link to post Share on other sites
zppblood 0 Posted May 28, 2007 Report Share Posted May 28, 2007 Maybe this could work. <?php $start=97; for ($i=0; $i<=25; $i++) { $letter=chr($start+$i); }?> <?php $start=97; for ($i=0; $i<=25; $i++) { for ($j=0; $j<=25; $j++) { $letter=chr($start+$i).chr($start+$j); } }?> Quote Link to post Share on other sites
Matpatnik 1 Posted May 28, 2007 Author Report Share Posted May 28, 2007 Maybe this could work.<?php $start=97; for ($i=0; $i<=25; $i++) { for ($j=0; $j<=25; $j++) { $letter=chr($start+$i).chr($start+$j); } }?> Thank you, I will still have to call every table but at least now I know how Quote Link to post Share on other sites
henryhenry 0 Posted May 28, 2007 Report Share Posted May 28, 2007 Hopefully this hasn't double-posted...MySQL stores database information in (at least in my version (5.1 I think) ) a database called 'information_schema'. You can select all the table names with this query:SELECT table_name FROM tables;(you must select the correct database with "USE information_schema")You could use SQL to select only the tables that start with 'mots_' or whatever your tables are called. Or you could get them all and do that with PHP.I think mma_fighter's method is very clever for the loop. I used a less clever method with a switch in a function when I did something like this. Maybe I'll change it Quote Link to post Share on other sites
zppblood 0 Posted May 28, 2007 Report Share Posted May 28, 2007 http://us.php.net/manual/en/function.mysql-list-tables.php Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.