Jump to content

auto increase letters


Matpatnik

Recommended Posts

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

Link to comment
Share on other sites

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 :)
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...