|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Script to add entire year in table
Hi,
Im in need of a script that would insert all the dates from 2007 into a dates table. the way the table is set out is like this: LOGDATE YEAR NO WEEK NO DAYNo 01/01/2007 2007 1 1 the table is called tblDates can anyone suggest the best way to add the entire year (without having to add it all manually!!) Thanks! |
|
#2
|
||||
|
||||
|
You should ask this in the MySQL forum (if that's the DB you're using), or the PHP forum (if that's the scripting language you're using. It's a trivial PHP problem. But I don't know, maybe it can be done with a query as well.
|
|
#3
|
||||
|
||||
|
to which field? Log date or year?
the date functions differ from database to database, so there's no point in elaborating ...
__________________
--Ax without exception, there is no rule ... The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones ![]() 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. -- Jamie Zawinski Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ... |
|
#4
|
|||
|
|||
|
Code:
<?php
/// log it as a date in mysql, not day, month, year
/// 365 is number of days - this could be 1825 for 3 years if you want
/// it will automatically calculate the month and year just from incremeting the number of days
for ( $counter = 0; $counter >= 365; $counter += 1) {
$toinsert = mktime(0,0,0,date("m"),date("d")+$counter,date("Y"));
$value = "WHATEVER VALUE YOU WANT HERE";
$sql = "INSERT into tablename VALUES('".date("Y-n-j", $toinsert)."', '".$value."');";
@mysql_query($sql);
}
?>
p.s. code untested, as modified it on here from one of my scripts Forgot to mention you will need your dbconnection password and select db info above this. or simply: Replace: Code:
@mysql_query($sql); With: Code:
echo $sql; and copy and paste it from your browser and paste it into phpmyadmin as a sql command |
![]() |
| Viewing: Dev Shed Forums > Web Site Management > Scripts > Script to add entire year in table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|