angelodev Posted May 4, 2007 Share Posted May 4, 2007 If ((!$_GET['month']) && (!$_GET['year'])) { $month = Date("n"); $year = Date("Y"); } else { $month = $_GET['month']; $year = $_GET['year']; } //Month calculation calculated $timestamp = mktime(0, 0, 0, $month, 1, $year); $monthname = date("F", $timestamp); ?> <table class="calendar"> <tr> <td colspan="7"><?php echo $month ?></td> </tr> <tr> <td>Su</td> <td>M</td> <td>Tu</td> <td>W</td> <td>Th</td> <td>F</td> <td>Sa</td> </tr> </table> I would like to create a calendar top header with this ode. But it does not work!! Have you any advice? PS: these are my first PHP code lines Quote Link to comment Share on other sites More sharing options...
dbo Posted May 4, 2007 Share Posted May 4, 2007 Can you describe what does not work means please? Just glancing at the code it looks pretty close. If you can provide more insight as to what it's doing perhaps we can provide you with a better answer. Quote Link to comment Share on other sites More sharing options...
Rottingham Posted May 4, 2007 Share Posted May 4, 2007 I see one recommendation to make with your code that may help... If ((!$_GET['month']) && (!$_GET['year'])) { $month = Date("n"); $year = Date("Y"); } else { $month = $_GET['month']; $year = $_GET['year']; } The IF line checking for the availability of Month and Year is actually just checking for a TRUE value, which is faulty if you are trying to see if the variable has been set. Use the following code for clarity and probably better results on your IF statement. if(isset($_GET['month']) == FALSE && isset($_GET['year']) == FALSE) { $month = date('n'); $year = date('y'); } else { $month = $_GET['month']; $year = $_GET['year']; } Now, if you want to be really fancy, you can use the conditional operators ? and : This really cleans up your code lines, but sometimes isn't as clear to the reader of your code. $month = isset($_GET['month']) ? $_GET['month'] : date('n'); $year = isset($_GET['year']) ? $_GET['year'] : date('y'); To help you understand the last code snippet, it is a single line IF. $RETURN_VALUE = (CONDITION) ? IF_TRUE RETURN VALUE : IF_FALSE RETURN VALUE; So, $month = (IF THE MONTH VALUE IS SET) ? $_GET['month']: ELSE RETURN date('n'); Quote Link to comment Share on other sites More sharing options...
angelodev Posted May 4, 2007 Author Share Posted May 4, 2007 Ok, I agree wth you. My last post wasn't clear.... <table class="calendar"> <tr> <td colspan="7"><?php echo $month ?></td> </tr> <tr> <td>Su</td> <td>M</td> <td>Tu</td> <td>W</td> <td>Th</td> <td>F</td> <td>Sa</td> </tr> The echo line doesn't print the month name at the table's top. I think that the variale is correcly load. A litte ajax script call this php functionfor load a dynamic calendar i the home page. Quote Link to comment Share on other sites More sharing options...
wayne0126 Posted May 5, 2007 Share Posted May 5, 2007 Hey <td colspan="7"><?php echo $month ?></td> You missed a spot. <td colspan="7"><?php echo $month; ?></td> The " ; " . Quote Link to comment Share on other sites More sharing options...
marcus Posted May 5, 2007 Share Posted May 5, 2007 The ';' isn't completely necassary in that situation. Best to check if the variable isn't defined: if (!$_GET['month']) && !$_GET['year'])) { $month = date('n'); $year = date('Y'); } else{ $month = $_GET['month']; $year = $_GET['year']; } Quote Link to comment Share on other sites More sharing options...
angelodev Posted May 5, 2007 Author Share Posted May 5, 2007 Also with the variables definet it does not wor. The strange think is that the echo function insite the tale doesn't print anything: either with the $month var and a fixed string. I thinj that the trouble is located there. echo "Ciao!" -> doesn't print anything in the first row Quote Link to comment Share on other sites More sharing options...
angelodev Posted May 5, 2007 Author Share Posted May 5, 2007 If yo cut ad past this code <?php //calendar.php //Check if the month and year values exist if ((!$_GET['month']) && (!$_GET['year'])) { $month = date ("n"); $year = date ("Y"); } else { $month = $_GET['month']; $year = $_GET['year']; } //Calculate the viewed month $timestamp = mktime (0, 0, 0, $month, 1, $year); $monthname = date("F", $timestamp); echo $monthname; ?> into your script: $monthname is displayed? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.