I still can't get my head round this.
function create_table($mmyy) {
// create a new archive table with all the entries from blog_entry for a
//certain month
$table_name = "blog_entry".$mmyy;
$query = "CREATE TABLE `imhotep`.`$table_name` ( `blog_entry_key` mediumint( 8 ) unsigned zerofill NOT NULL auto_increment, `blog_scribble` longtext NOT NULL , `blog_timestamp` timestamp( 14 ) NOT NULL , `mmyy` varchar( 4 ) NOT NULL default '', PRIMARY KEY ( `blog_entry_key` ) , KEY `blog_timestamp` ( `blog_timestamp` ) ) TYPE = MYISAM ";
$result = (mysql_query($query));
if(!$result) error_message(sql_error());
$query ="INSERT INTO `imhotep`.`$table_name`
SELECT * FROM `imhotep`.`blog_entry`
WHERE mmyy = $mmyy";
$result = (mysql_query($query));
if(!$result) error_message(sql_error());
//create entry for the month in table blog_archive_id
$query = "INSERT into imhotep.blog_archive_id
VALUES (NULL,
$mmyy)";
$result = (mysql_query($query));
if(!$result) error_message(sql_error());
}
As you can see I format a table name "blog_entry".$mmyy At this stage $mmyy retains the leading zero e.g 0503. However, by the time I use it to insert into the table blog_archive_id it has lost the leading zero and becomes 503. Is the previous query doing this?
Sorry that my php code is not highlighted but I only seem to be able to paste about 30 characters at a time into the code highlighter alert box - another problem - sigh.