0

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 {
// CONSTRUCTING SQL STATEMENT USING
// UNION ALL
}

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

2
Contributors
1
Reply
22
Views
4 Years
Discussion Span
Last Post by diafol
0

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.

//EDIT

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.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.