You are here: Re: passing args to php page « PHP Language « IT news, forums, messages
Re: passing args to php page

Posted by Ric on 01/03/07 12:06

Troy Piggins schrieb:
> * Ric wrote:
>> Troy Piggins schrieb:
>>> I have a php page[1] with 'includes'[2]. The page correctly
>>> displays a calendar of the current month and current year if
>>> $Month and $Year are not assigned, but if I try to call the page
>>> with blog.php?Month=12&Year=2006 in the URL nothing seems to
>>> change. Any ideas?
>> Yes it is because you never get these parameters, see below:
>>
>>> [1] blog.php
>>> [snip html headers etc]
>>> <?php
>>> $Title= "Blog";
>>> include( "calendar.php");
>>> ?>
>>> [snip body and footers etc]
>>>
>>> [2] calendar.php
>>> <?php
>>>
>>> if( !$Month) $Month= date( "m");
>>> if( !$Year) $Year= date( "Y");
>> if(isset($_GET['Month']){
>> $Month = $_GET['Month'];
>> }
>>
>> I prefer this version:
>>
>> isset($_GET["Month"]) ? $Month = $_GET["Month"] : $Month = "";
>>
>> Same for Year.
>
> Thanks - this worked:
>
> if( isset( $_GET['Month'])) {
> $Month= $_GET['Month'];
> } else {
> $Month= date( "m");
> }
>
> if( isset( $_GET['Year'])) {
> $Year= $_GET['Year'];
> } else {
> $Year= date( "Y");
> }
>
> At first I was confused because the docs I was reading talked
> about $_GET and forms, but I am not using any forms. But just
> plugged in the above and it worked anyway. Thanks again.
>
Because if you call a url with ?var1=value1 it is a get request the same
thing a form does when action is set to get, only difference is that
form sets these var/values from form fields .
If you submit forms via post, the url will not change, but the data
transfered in the background.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация