Soldato
- Joined
- 22 Aug 2005
- Posts
- 8,971
- Location
- Clydebank
hi all
I have this code, generating VIEWS in my database.
Essentially I have a 200,000+ row table, which has a few hundred more rows ('apps') added to it each day.
These newly added apps are compared against all previously entered apps, and 2 results are found: Apps previously entered into the database, and 'new' apps, i.e. apps the database has never seen before. (per date)
Now that's pretty straightforward. here's the function
OK, I know it needs a bit of tidying, but when I was testing with only 30 rows, this worked OK. Now that I have 200,000 records i am getting timeout errors. Even in phpmyadmin. When I click to view the OLD view (i.e. 'SELECT * FROM ' . $tablename . '_OLD ORDER BY id DESC'
The error in php myadmin occurs after only drawing 107 records tos the screen...
These tables should have only less than 3-400 records max.
So is there a better way to query the system ? Something more efficient? Should I be creating tables rather than views?
Need anymore info?
thanks all
I have this code, generating VIEWS in my database.
Essentially I have a 200,000+ row table, which has a few hundred more rows ('apps') added to it each day.
These newly added apps are compared against all previously entered apps, and 2 results are found: Apps previously entered into the database, and 'new' apps, i.e. apps the database has never seen before. (per date)
Now that's pretty straightforward. here's the function
PHP:
function getApps($date_value, $querystring) {
$tablename = 'ts' . strtotime ( $date_value );
$querystringtmp = 'CREATE OR REPLACE VIEW ' . $tablename .
' AS SELECT main_table.id, main_table.app_no, main_table.date, main_table.council' .
' FROM main_table WHERE main_table.date = \''. $date_value . '\'';
print $querystringtmp;
mysql_query($querystringtmp) or trigger_error(mysql_error());
$querystringtmp = 'CREATE OR REPLACE VIEW upto_' . $tablename .
' AS SELECT main_table.id, main_table.app_no, main_table.date, main_table.council' .
' FROM main_table WHERE main_table.date < \''. $date_value . '\'';
print $querystringtmp;
mysql_query($querystringtmp) or trigger_error(mysql_error());
$querystringtmp = 'CREATE OR REPLACE VIEW ' . $tablename . '_NEW AS SELECT ' . $tablename . '.id, ' . $tablename . '.app_no, ' . $tablename . '.date, ' . $tablename . '.council
FROM ' . $tablename . ' LEFT JOIN upto_' . $tablename . ' ON ' . $tablename . '.app_no = upto_' . $tablename . '.app_no
WHERE upto_' . $tablename . '.app_no Is Null';
print $querystringtmp;
mysql_query($querystringtmp) or trigger_error(mysql_error());
$querystringtmp = 'CREATE OR REPLACE VIEW ' . $tablename . '_OLD AS SELECT ' . $tablename . '.id, ' . $tablename . '.app_no, ' . $tablename . '.date, ' . $tablename . '.council
FROM ' . $tablename . ' LEFT JOIN upto_' . $tablename . ' ON ' . $tablename. '.app_no = upto_' . $tablename . '.app_no
WHERE upto_' . $tablename . '.app_no Is NOT Null';
print $querystringtmp;
mysql_query($querystringtmp) or trigger_error(mysql_error());
/* $querystringOLD='SELECT * FROM ' . $tablename . '_OLD ORDER BY id DESC LIMIT ' . $start_from .', ' . $records_per_page ;
$querystringNEW='SELECT * FROM ' . $tablename . '_NEW ORDER BY id DESC LIMIT ' . $start_from .', ' . $records_per_page ;
*/
$querystringOLD='SELECT * FROM ' . $tablename . '_OLD ORDER BY id DESC';
$querystringNEW='SELECT * FROM ' . $tablename . '_NEW ORDER BY id DESC';
$querystring_tmp = array( $tablename => array( 'New' => $querystringNEW,
'Old' => $querystringOLD
)
);
if (!isset ($querystring)) {
$querystring = $querystring_tmp;
} else {
$querystring = array_merge($querystring, $querystring_tmp);
};
echo '<P>';
print_r($querystring);
return $querystring;
}
OK, I know it needs a bit of tidying, but when I was testing with only 30 rows, this worked OK. Now that I have 200,000 records i am getting timeout errors. Even in phpmyadmin. When I click to view the OLD view (i.e. 'SELECT * FROM ' . $tablename . '_OLD ORDER BY id DESC'

The error in php myadmin occurs after only drawing 107 records tos the screen...
These tables should have only less than 3-400 records max.
So is there a better way to query the system ? Something more efficient? Should I be creating tables rather than views?
Need anymore info?
thanks all