Jump to content

Need help with QueryString ..


spacepoet

Recommended Posts

Hi:

 

How can I build a querystring (or whatever I need to do to solve my issue) to pull in the month and year?

 

Meaning:

 

I have this link:

Entertainment.php

 

which goes to a dynamic calendar, which works fine except it does not show the events because I think it replies

on getting the current month and year.

 

When I click on a "Next Month" and the click back to the current month, the URL is:

Entertainment.php?month=4&year=2011

 

and the events then display properly in the calendar.

 

How do I properly build a URL for this?

 

The calendar code looks like this:

<?php
ob_start();
$today = date("M Y");
?>

...

<head>
<script>
function show_evt(m,y,day){  
    location.href = "<?=$_SERVER['PHP_SELF'];?>?month=" + m + "&year=" + y + "&day=" + day;
}

function goLastMonth(month, year)
{

if(month == 1)
{
--year;
month = 13;
}

document.location.href =  '<?=basename($_SERVER['PHP_SELF']);?>?month='+(month-1)+'&year='+year;
} 
function goNextMonth(month, year)
{

if(month == 12)
{
++year;
month = 0;
}

document.location.href = '<?=basename($_SERVER['PHP_SELF']);?>?month='+(month+1)+'&year='+year;
} 
</script>
</head>

...

<p>

<?php 

$date =time ();

$day = (isset($_GET['day'])) ? $_GET['day'] : date('d', $date);
$month = (isset($_GET['month'])) ? $_GET['month'] : date('m', $date);
$year = (isset($_GET['year'])) ? $_GET['year'] : date('Y', $date);

$first_day = mktime(0,0,0,$month, 1, $year);

$title = date('F', $first_day); 

$day_of_week = date('D', $first_day);

switch($day_of_week){ 
     case "Sun": $blank = 0; break; 
     case "Mon": $blank = 1; break; 
     case "Tue": $blank = 2; break; 
     case "Wed": $blank = 3; break; 
     case "Thu": $blank = 4; break; 
     case "Fri": $blank = 5; break; 
     case "Sat": $blank = 6; break; 
}


$days_in_month = cal_days_in_month(0, $month, $year); 

?>
<table class="tableClass">
<tr class="field-bg-color">
     <th class="eventLeftArrow"><a href="javascript: void(0);" onClick="goLastMonth(<?php echo $month . ", " . $year; ?>)"><<<</a></th>
     <th colspan="5" class="eventHeader"><?=$title. " " . $year;?></th>
    <th class="eventRightArrow"><a href="javascript: void(0);" onClick="goNextMonth(<?php echo $month . ", " . $year; ?>)">>>></a></th>
</tr>
<tr class="calDates">
     <td>S</td>
     <td>M</td>
     <td>T</td>
     <td>W</td>
     <td>T</td>
     <td>F</td>
     <td class="lastOne">S</td>
</tr>
<?php

$day_count = 1;

?>
<tr>
<?php
while ( $blank > 0 ) { 
?>
<td>      </td>
<?php 
     $blank = $blank-1; 
     $day_count++;
} 

$day_num = 1;

while ( $day_num <= $days_in_month ) { 
    $sql = "select count(calName) as evt_count from calTbl where calDate ='" . $month . '/' . $day_num . '/' . $year . "'";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
        if($row['evt_count'] >= 1){
    ?>
            <td align="center" style="cursor:hand;cursor:pointer;background-color:#FF6A6A;text-align:center;" onclick="show_evt('<?=$month;?>','<?=$year;?>','<?=$day_num;?>');">
            <div class="brown-bg-color cal-head-text white-text bold-text"><?=$day_num;?></div>      
            
    <?php
        $sql = "select * from calTbl where calDate ='" . $month . '/' . $day_num . '/' . $year . "'"; 
        $result = mysql_query($sql);
            while($row = mysql_fetch_array($result)){
                ?>
                <a href="<?=$_SERVER['PHP_SELF'];?>?month=<?=$month;?>&year=<?=$year;?>&day=<?=$day_num;?>"><?=$row['calName'];?></a></br>
            <?
            }
        }else{
    ?>
            <td>
            <div class="brown-bg-color cal-head-text"><?=$day_num;?></div>      
    <?php
        }
    }
?>
    </td>
<?php 
$day_num++; 
$day_count++;

if ($day_count > 7){
?>
</tr><tr>
<?php
$day_count = 1;
}
} 

while ( $day_count >1 && $day_count <=7 ) { 
?>
<td> </td> 
<?php
$day_count++; 
} 
?>
</tr></table> 
<?php

if(isset($_GET['day'])){
         $sql = "select * from calTbl where calDate ='" . $month . '/' . $_GET['day'] . '/' . $year . "'";
         $result = mysql_query($sql);
         echo '<table class="data-table-class">';
         echo '<th>Event Name</th><th>Event Desc</th>';
        while($row = mysql_fetch_array($result)){
            echo '<tr><td>'. $row['calName'] . '</td><td>' . $row['calDesc'] . '</td></tr>';
        }
        echo '</table>';
}
?>
      
<div class="myClear"></div>

<?php
    ob_flush();
?>



</p>

 

 

Can anyone help me out? This is the last part and I am good to go!

 

Thanks!

 

 

 

 

Link to comment
Share on other sites

Hi:

 

What I need to have happen is when the link is clicked:

Entertainment.php

 

It goes to that page with the final URL looking like:

Entertainment.php?month=4&year=2011

 

Where the URL will always write the current month and year.

 

Does this make sense?

 

Thanks!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.