FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » using same variable twice on same page
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: using same variable twice on same page [message #171197 is a reply to message #171194] Wed, 29 December 2010 11:25 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Adrienne Boswell wrote:

> richard [wrote]:
>> Everything I have looked at so far talks of how to use one variable
> ONCE!
^^
Please get a decent newsreader that does not produce broken quotes.

> […]
> <?php
>
> if(isset($_GET['year']))
> {$year = $_GET['year'];
> //do some testing to make sure the value is what you want}
> else
> {$year = 1960;}
>
> echo "<p>The initial year is ".$year.".</p>";
>
> echo "<p>Loop 10 years:</p>";
>
> for($i=0;$i<10;++$i)
> {
> echo "<p>The year is now ".$year+$i.".</p>";
> }
> ?>

The following might be slightly less confusing, and slightly more efficient:

<?php
$year = (isset($_GET['year'])) ? $_GET['year'] : 1960;

/* do some testing to make sure the value is what you want */
?>

<p>The initial year is <?php echo $year; ?>.</p>

<p>Loop 10 years:</p>

<?php
for ($i = $year, $maxYear = $year + 10;
$i < $maxYear;
++$i)
{
?><p>The year is now <?php echo $i; ?>.</p><?php
}
?>


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: AND in the if statement
Next Topic: login script using file, not mysql
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 22:05:25 GMT 2024

Total time taken to generate the page: 0.04429 seconds