Page 1 of 1
Creating variable from date
Posted: Sun Aug 02, 2009 1:20 pm
by clonemaster
Hi,
Trying to automate some things with a php script, like duplicating table (structure only) and name it with 'tablename
_09' for this year, tablename
_10 for next year and so on.
Got the part done where I define the year, but how to shorten it to _"last two numbers of year"
Code: Select all
<?php
define('CURRENT_YEAR', date('Y'));
define('PREVIOUS_YEAR', date('Y') - 1 );
define('PRE_PREVIOUS_YEAR', date('Y') - 2 );
define('NEXT_YEAR',date('Y') + 1 );
function listYears() {
echo 'Twee jaar geleden was '.PRE_PREVIOUS_YEAR.'<br />';
echo 'Vorig Jaar was '.PREVIOUS_YEAR.'<br />';
echo 'Huidige Jaar is '.CURRENT_YEAR.'<br />';
echo 'Volgend jaar is '.NEXT_YEAR.'<br />';
}
listYears();
?>
O, and now I manually copy the tables, isn't there a piece of php for like copy 'tablename' to 'newtablename' ?
Thanks already..

Re: Creating variable from date
Posted: Sun Aug 02, 2009 1:49 pm
by jackpf
Code: Select all
$two_digits = substr($date, strlen($date) - 2, 2);
Should shorted the date to the last two digits.
And you can copy a table by doing,
Code: Select all
INSERT INTO `new_table` SELECT * FROM `old_table`
I think.
Re: Creating variable from date
Posted: Sun Aug 02, 2009 1:57 pm
by califdon
Your concept of creating a new table for each year is bad database design in nearly every conceivable circumstance. Unless you're dealing with many millions of records per year (and even then!), there's no advantage to dividing similar data into different tables, and many disadvantages. With today's capabilities of software and hardware, much more is lost in dealing with multiple tables than could possibly be gained by having smaller tables. Use queries to select the data you want for each purpose, but don't split your data arbitrarily.
Re: Creating variable from date
Posted: Sun Aug 02, 2009 2:53 pm
by jackpf
That's true - I should have said that.

Re: Creating variable from date
Posted: Sun Aug 02, 2009 3:58 pm
by clonemaster
I understand what you say, but this is the way it is..
I'm helping some guys with their data..
I think it is designed this way, because the actual data is coming from an MS Access db, which is used by several clubs al over the country giving all kinds of problems to deal with.. including a yearly classification of all contesters from a whole year. The design of the MS db was done by someone else long ago.
Thanks for you reply though.
And thank you jack for yuor solution, I'll try it.
Re: Creating variable from date
Posted: Sun Aug 02, 2009 4:01 pm
by califdon
jackpf wrote:That's true - I should have said that.

Don't worry, you're doing fine here. Look at my signature. There's also an old story about the 2 bulls on the hill, looking down on the meadow where a herd of cows was grazing. The young bull starts pawing the ground and snorting and says, "C'mon, let's run down the hill and get us a heifer!" The old bull calmly turns to the younger one and says, "Nah, let's WALK down the hill and get 'em ALL!"
Re: Creating variable from date
Posted: Sun Aug 02, 2009 4:06 pm
by clonemaster
Ehhh
where do I put this code jack ..?
Re: Creating variable from date
Posted: Sun Aug 02, 2009 4:26 pm
by jackpf
califdon wrote:jackpf wrote:That's true - I should have said that.

Don't worry, you're doing fine here. Look at my signature. There's also an old story about the 2 bulls on the hill, looking down on the meadow where a herd of cows was grazing. The young bull starts pawing the ground and snorting and says, "C'mon, let's run down the hill and get us a heifer!" The old bull calmly turns to the younger one and says, "Nah, let's WALK down the hill and get 'em ALL!"
Hehe that's pretty cool. You seem like a very philosophical guy

Thanks for the support...it means a lot.
clonemaster wrote:Ehhh
where do I put this code jack ..?
And what code would you be referring to? I posted some PHP and some SQL. Obviously the PHP should go wherever you're defining your dates, and the SQL should go in a mysql_query().
Hope this helps,
Jack.
Re: Creating variable from date
Posted: Sun Aug 02, 2009 4:40 pm
by clonemaster
Well, the php I posted does echo out some yearnumbers, but how do you transform this code to so the output is shortened?
Sorry for being noob..
Re: Creating variable from date
Posted: Mon Aug 03, 2009 7:07 am
by jackpf
You mean the date shortened?
jackpf wrote:Code: Select all
$two_digits = substr($date, strlen($date) - 2, 2);
Should shorted the date to the last two digits.
Does that not work?
Re: Creating variable from date
Posted: Mon Aug 03, 2009 9:18 am
by clonemaster
I get Undefined variable: date
Re: Creating variable from date
Posted: Mon Aug 03, 2009 9:40 am
by jackpf
Well yeah, you need to use your own variables...........
