Page 1 of 1

how to pass a param that requires a param in the ulr

Posted: Mon May 16, 2005 9:54 pm
by maulesh
I am new to PHP and programming for that matter. The problem i am facing is that I want to pass a parameter in the link but this parameter takes in another parameter itself. eg:

Code: Select all

<a href=&quote;index.php?var1=test.php?var2=12345&quote;>link</a>
as you can see the var1 is assigned the value of another page (test.php) but test.php itself requires a parameter passed in for correct display. How can i achieve this?

My apologies if this has already been answered but I have googled as well as searched this forum quite a bit and only after that decided to post this question.

thanks,
- maulesh

Posted: Mon May 16, 2005 9:59 pm
by John Cartwright
I don't really get what you are trying to accomplish. Maybe you could clarify that.
Either way, it is invalid.

To pass multiple parameters you use a & instead of multiple ?'s

Code: Select all

<a href=&quote;index.php?var1=test.php&var2=12345&quote;>link</a>

Posted: Mon May 16, 2005 10:11 pm
by SBro
As I understand it what you are doing is correct. You would do it as follows:

Code: Select all

&lt;a href=&quote;index.php?var1=test.php?var2=12345&quote;&gt;link&lt;/a&gt;
index.php

Code: Select all

$var1 = $_GET['var1']; // $var1 would now be: test.php?var2=12345
If you then use $var1 as a link somewhere, in test.php you would do the same thing again:

test.php

Code: Select all

$var2 = $_GET['var2']; // $var2 would now be: 12345

Posted: Tue May 17, 2005 12:12 am
by Burrito
not sure I understand exactly either...but If you're just trying to use var1 as a link somewhere on your "action" page, you could do something like this

Code: Select all

echo "<a href=\"".$_GET['var1']."?newvar=".$_GET['var2']."\">click here</a>";

Posted: Thu May 19, 2005 1:33 pm
by maulesh
Thanks for your quick reply guys. I had trouble with my pc and couldnt access this forum. Let me try to clerify things a bit. I have a 3-col css layout for my website. The center page displays the contents. Now, I have a calendar on the right side of the page where dates with events are linked. Now when the page renders at first the url will look something like

http://www.mydomain.com/index.php?page=welcome.html

then clicking on one of the dates from the calendar, the url should change to

http://www.mydomain.com/index.php?page= ... e=20050520

In my case it just shows me a blank page in the center. So I am thinking that if the variables used in calendar.php are evaluated first then everything is sent to index.php then the page will display correctly. However, I am stumped as to how can i achieve that. Hopefully this makes more sense. I will try to setup a test page to show what i mean but that may take sometime.

thanks,
- Maulesh

Posted: Thu May 19, 2005 4:00 pm
by hongco
post your codes up!

Posted: Thu May 19, 2005 6:00 pm
by maulesh
Here is the code

Code: Select all

PHP Version: 4.3.11
Display Errors: On
Error Level: E_ALL
Register Globals: Off
index.php

Code: Select all

<?php
include "header.php";
include "php/orgcal/include/main.php";

extract($_GET);
if (empty($page))
  $page = "body_content/welcome.html";
?>
<!--Left Content -->
<div id="leftcontent">
  <div id="contentdivs">
    <?php include "menu.php"; ?>
  </div>
</div> <!-- end div leftcontent -->

<!--Right Content -->
<div id="rightcontent">
  <div id="contentdivs">
    <?php include "php/orgcal/miniCal.php"; ?>    <---------- The part in question
  </div>
</div>

<!--Main Content -->
<div id="centercontent">
  <div id="contentdivs">
    <?php include $page; ?>
  </div>
</div>
<?php
include "footer.php";
?>
miniCal.php

Code: Select all

<?
if( !isset($_REQUEST['date']) )
  $date = OrgCal::getTodaysDate();
else
  $date = $_REQUEST['date'];

$mini = new OCMiniCal();
$body = $mini->drawMiniCalTable( $date, $return = true, "orgcal/" );

echo "<table class='box' cellspacing='0' width= 100%'> <tr class ='boxTitle'> <td>Calendar</td></tr> <tr class='boxContent'> <td>$body</td></tr> </table>";
?>
OCMiniCal.php

The code on line 82 generates the link so the link becomes

Code: Select all

http://localhost/index.php?page=php/orgcal/view.php?view=day&amp;date=20050521

Code: Select all

<?php
/**
 * OCMiniCal
 * 
 * @author Kevin Southworth <southwo8@msu.edu>
 * @copyright Copyright (c) 2004
 * @version 0.1
 * @since 2004-04-18
 * @access public
 **/
class OCMiniCal extends OCMonth {

	/**
	 * OCMiniCal::OCMiniCal()
	 * 
	 * @return 
	 **/
	function OCMiniCal() {
		$this->OrgCal();	// parent constructor				
	}
	
	/**
	 * OCMiniCal::drawMiniCalTable()
	 * 
	 * @param $date
	 * @param boolean $returnHtml
	 * @return 
	 **/
	function drawMiniCalTable( $date, $returnHtml = false ) {
		list($year,$month,$day) = $this->decDateStr($date);
		$dstr = $this->encDateStr( $year, $month, 1 );
				
		$wkstart_t = $this->getWeekStart($dstr);		
		$monthstart_t = $this->getMonthStart( $year, $month );
		$monthend_t = $this->getMonthEnd( $year, $month );
		
		// Pre-load event data - this is REQUIRED for getDateEvents() to return anything!
		$this->fillEventCache( $this->stampToString($monthstart_t), $this->stampToString($monthend_t) );
		
		$html = "\n<div class=\"center\">\n<table class=\"miniCal border\" cellspacing=\"0\" cellpadding=\"0\">\n";
		#### Table heading ####
		$monthName = $this->getMonthName( $month );
		$prevLink = '<a href="'.$_SERVER['PHP_SELF'].'?date='.$this->getPreviousMonth($dstr).'" class="previous"><</a>';
		$nextLink = '<a href="'.$_SERVER['PHP_SELF'].'?date='.$this->getNextMonth($dstr).'" class="next">></a>';		
		$html .= '<tr> <td class="miniCalHeader">'.$prevLink.'</td>';
		$html .= '<td colspan="5" class="miniCalHeader">'.$monthName.' '.$year.'</td>';
		$html .= '<td class="miniCalHeader">'.$nextLink.'</td> </tr>';
		#### Day headings ####
		$headings = '<tr>';
		foreach( $this->getWeekdayNames('abbrev') as $dayName ) {
			$headings .= '<td class="colHeader">'.$dayName.'</td>';
		}
		$headings .= '</tr>';
		$html .= $headings;
		
		### day cells output ###
		$month_it = new OCMonthIterator($wkstart_t,$monthstart_t,$monthend_t);
		while( $dateStr = $month_it->moveNext() ) {
			list(,,$day) = $this->decDateStr($dateStr);
			$todayDateStr = $this->getTodaysDate();
			
			if( $month_it->isFirstInRow() ) {
				$html .= "<tr>\n";
			}
			
			if( $dateStr == 'empty' ) {	// no events for this day
				$html .= "<td>&nbsp;</td>\n";
			} else {	// events exist for this day
				$date_t = $this->stringToStamp( $dateStr );
				$classes = '';
				if( $this->dateIsWeekend( $date_t ) )
					$classes = ' weekend';
				if( $dateStr == $todayDateStr ) {
					$classes = ' curDay';
				}	
				
				### day cells ###
				$dateEvents = $this->getDateEvents( $dateStr );
				$dayNum = sprintf("%d",$day);
				$dayLink = $dayNum;
				if( (sizeof($dateEvents) > 0) && OrgCalAuth::checkViewAuth(-1) ) {
					$dayLink = '<a href="view.php?view=day&date='.$dateStr.'" class="hasEvents">'.$dayNum.'</a>';
					if( $dateStr != $todayDateStr )
						$classes .= ' hasEvents';
				}
   			    $html .= '<td class="center miniCal normalDay'.$classes.'">';
				$html .= $dayLink;
				$html .= '</td>';
			}
			
			if( $month_it->isLastInRow() ) {
				$html .= "</tr>\n";
			}			
		} // end while loop for day cells
		$html .= '</table> </div>';

		return $html;
	}
		
	### Variables ###
	
}

?>
view.php

Note: I have tried to modify below code to accomodate my needs and so not all the variables are being used.

Code: Select all

<?php
/* view.php
* 
* Handles the display of 'views' for OrgCal
* (e.g. Month, Week, Day)
*/
require_once 'include/main.php';

if( !isset($_REQUEST['date']) )
	$date = OrgCal::getTodaysDate();
else
	$date = $_REQUEST['date'];
	
// Controller
$view = $_REQUEST['view'];
switch( $view ) {	
	case 'event':
		$title = 'OrgCal : Event View';	
		$sheets = OrgCalConfig::getEventStylesheets();		
		$eventObj = new OCEvent( $_REQUEST['id'] );
		$html = $eventObj->drawEventTable( $return = true );
		$html .= '<br />'.$eventObj->drawEventLinks( $date, $override = false, $return = true );
		$body = $html;
		break;
	case 'day':
		$title = 'OrgCal : Day View';
		$sheets = OrgCalConfig::getDayStylesheets();
		$dayObj = new OCDay();
		$html = $dayObj->drawDayTable( $date, $return = true );
		$body = $html;
		$body .= '<br />'.$dayObj->drawNavTable( $date, $return = true );
		break;
	case 'week':
		$title = 'OrgCal : Week View';
		$sheets = OrgCalConfig::getWeekStylesheets();
		$weekObj = new OCWeek();
		$body = $weekObj->drawWeekTable( $date, $return = true );
		$body .= '<br />'.$weekObj->drawNavTable( $date, $return = true );
		break;
	case 'month':
	default:
		$title = 'OrgCal : Month View';
		$sheets = OrgCalConfig::getMonthStylesheets();
		$monthObj = new OCMonth();
		$body = $monthObj->drawMonthTable( $date, $return = true );
		$body .= '<br />'.$monthObj->drawNavTable( $date, $return = true );
		$body .= '<br />'.OrgCalAuth::drawUserBox(true);
}
?>
<!-- div for overLib -->
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<?=$body?>

let me know if you need other parts of the code. I really appreciate all your help.

thanks,
- Maulesh

Posted: Fri Jan 26, 2007 12:39 am
by wiredkso
Hi, I am the original author/creator of the OrgCal php calendar, although I created it a LONG time ago ;) But if you need any more help let me know. Also, if you're using OrgCal for a production website I'd love to check out the url too :) always fun to see your work making it's way around the internet

Posted: Fri Jan 26, 2007 12:49 am
by volka
I guess urlencode is what you're looking for.