Hi All,

I want to select rows from dynamic created tables i.e we have tables like web_analytics_mm_yy(ex: web_analytics_06_13, web_analytics_05_13, web_analytics_04_13 and so on)
web_analytics -> table name
mm_yy -> month_year.
I know this can be acheived in PHP by using

for loop {

but is there any thing that can be done using mysql Query only?
and i want to know what is the best method to fetch data from multiple tables which are created dynamic.

Thx ppl

Member Avatar

I'd ask the question whether you need multiple tables in the first place. Why not one long table with a date field so you can filter on that?

but is there any thing that can be done using mysql Query only?

Why do you need this? What's wrong with php creating the SQL string for you? You, I assume need to have start date and end date range, provided, again, I assume by php.

You could extract all the relevant tables with a SHOW TABLES LIKE 'web_analytics_%', and then pick out the relevant ones with a loop to create yourt SQL statement, but it's all so very messy. I'd suggest the one long table for all your analytics. If concerned about the length, you could always run an archive routine to remove records of a certain age to an archive table.


Is this a school project? THis question has just been repeated here around the same time: http://www.daniweb.com/web-development/php/threads/459120/dyamic-fetch-multiple-table

Coincidence? I think not as both you and the other OP are from Karnataka.

Nothing wrong with that, except we do expect you to do some of the work yourself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.