Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I followed the codex page on how to make tables in the wordpress database with a plugin and was able to understand and get it to work However, the plugin I'm developing has the need for many tables along with joining tables and to code each table individually would be time consuming to say the least.

Is there a way to create a batch of tables using an array() and loop function?

share|improve this question
    
Are you talking about MySQL tables? –  s_ha_dum May 24 '13 at 18:17
    
Yes, MySQL tables that are created from a php plugin. Here's the codex page that I modeled my plugin after codex.wordpress.org/Creating_Tables_with_Plugins –  sdgenxr May 24 '13 at 18:37
    
So what you are suggesting is that the best way to create a set of tables with an array is if each table had the same or similar fields? If that is the case, then I guess I'll be writing a script for each required table. Thanks! –  sdgenxr May 24 '13 at 18:50
    
Deleted that comment, posted an answer. –  s_ha_dum May 24 '13 at 18:53
add comment

1 Answer

up vote 0 down vote accepted

Well, yes, you can build your tables from an array but unless your tables are very similar, and they probably aren't, I don't know that doing that will be any less work than just writing out the definitions. That is, even if you used an array, you'd need to define each table from scratch and then Loop over the array to create the tables. You could save yourself some work, but I doubt it would be very much.

And you seem to be on the right track as far as the WordPress parts of this. That Codex page describes the canonical way to create tables, and you say you have that working.

You can cheat, though, and build your tables in PhpMyAdmin, then dump the definitions :)

share|improve this answer
    
Yes, it is working just fine. I did make a couple of changes as suggested by Dennis on this post wordpress.stackexchange.com/questions/4276/… –  sdgenxr May 24 '13 at 18:55
    
Thanks for the help. I ended up modeling the tables in MySQL Workbench and got the sql code from pushing out the new tables. –  sdgenxr Jun 1 '13 at 22:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.