Jump to content

Problems with sending variabels


postbil.com

Recommended Posts

Hey Phpfreaks.

 

I had a littel problem with my calendar script. I want i that way, then I click at the current day it reload the script (But only the calendar function) and remember which day there is selected.

The problem is then I reload the script it just display ”0”.

Can somebody please help me..

Postbil.com

<?php

    function calendar (){

// selecct the current timezone                                                                                                                                      

        date_default_timezone_set('Europe/Paris');  

// accept incoming URL parameter

        $timestamp = (isset($_GET['t'])) ? $_GET['t'] : time();

        $tsDM = (isset($_GET['tsDM'])); // Here I get the infomation about witch day the user had selected



// determine useful aspects of the requested month

        list($month, $day, $year) = explode('/', date('m/d/Y', $timestamp));

        $first_day_of_month = date('w', mktime(0, 0, 0, $month, 7, $year));

        $total_days = date('t', $timestamp);



// output table header

        echo '<h8>';

        echo '<table id="calendar">';

            echo '<tr id="calendar_header"><th colspan="7">';

                echo '<a href="' . htmlspecialchars($_SERVER['PHP_SELF']) . '?t=' .

                    strtotime('-1 month', $timestamp) . '"><</a>  ';

                echo date('F', $timestamp) . ' ' . $year;

                echo '  <a href="' . htmlspecialchars($_SERVER['PHP_SELF']) . '?t=' .

                    strtotime('+1 month', $timestamp) . '">></a>';

            echo '</th></tr>';

            echo '<tr><th>Man</th><th>Tir</th><th>Ons</th><th>Tor</th><th>Fre</th>' .

                '<th>Lør</th><th>Søn</th></tr>';



// output date cells

// here the loop started, to show the current day.

            $current = 1;

            while ($current <= $total_days){

                echo '<tr class="calendar_dates">';

                for ($i = 0; $i < 7; $i++){

                    if (($current == 1 && $i < $first_day_of_month) ||

                        ($current > $total_days)){

                            echo '<td class="empty">&nbsp</td>';

                            continue;                  

                    }

// find the correct timestamp at day.

                    $tsDMY = urlencode(mktime(0, 0, 0, $month, $current, $year)); // Here we save a timestamp with infomation about Month, Day, Year

                    $tsDM = urlencode(mktime(0, 0, 0, $month, $current, 0)); // Here we save a timestamp with infomation about Month, Day

// Print the actual date

                    echo "<td>";

// here I make a link.

// I use the "' . htmlspecialchars($_SERVER['PHP_SELF']) . '?tsDM=$tsDM" function before i want my page page only to reload the calender function, and remember witch day the user had selected.
The $tsDM have to be sendt 
                        echo '<centerI><a href="' . htmlspecialchars($_SERVER['PHP_SELF']) . '?tsDM=$tsDM">' . $current . $tsDM . '</a></center>';

                    echo "</td>";

                    $current++;

                }

                echo '</tr>';

            }

         echo '</table>';

         echo '</h8>';

         echo $tsDM; // Here I print the selected timestamp. 

}

Link to comment
https://forums.phpfreaks.com/topic/226554-problems-with-sending-variabels/
Share on other sites

Hi there, one of your problems is that here

 

$tsDM = (isset($_GET['tsDM']));

 

you are assigning the selected day to the local variable tsDM and then here

 

$tsDM = urlencode(mktime(0, 0, 0, $month, $current, 0));

 

you are replacing that value every time in the loop.

 

I think that this will help you, first in

echo '<centerI><a href="' . htmlspecialchars($_SERVER['PHP_SELF']) . '?tsDM=$tsDM">' . $current . $tsDM . '</a></center>';

The '?tsDM=$tsDM">'  is in single quotes so the value of $tsDM  wont be printed out, instead do it like this

echo '<centerI><a href="' . htmlspecialchars($_SERVER['PHP_SELF']) . '?tsDM='.$tsDM.'">' . $current . $tsDM . '</a></center>';

 

and at the end when you echo the $tsDM, if you want to print the day selected you can do it by echo $_GET['tsDM'].

 

Hope this will help you.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.