Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2004, 02:31 PM
Authorized User
 
Join Date: May 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default variable question


states.php---------------------------

<HTML>
<HEAD></HEAD>
<BODY>
<FORM ACTION="capitals.php" METHOD=POST>

<SELECT NAME=State>
<?php

$StatesOfTheUSA = array (1 => "Alabama", "Alaska", "Arizona"
for ($counter=1; $counter<51; $counter++) {
   echo"<OPTION>$StatesOfTheUSA[$counter]</OPTION>";
}
echo "</SELECT><BR><BR>";
for ($counter=1; $counter<51; $counter++) {
   echo"<INPUT TYPE=HIDDEN NAME='HiddenState[]'VALUE='$StatesOfTheUSA[$counter]'>";
}
echo "<INPUT TYPE=SUBMIT></FORM>";
?>
</BODY>
</HTML>

capitals.php--------------------------

<HTML>
<HEAD></HEAD>
<BODY>
<?php
$StateCapital = array (0 => "Montgomery", "Juneau", "Phoenix"
for ($counter=0; $counter<50; $counter++)
{
   if($HiddenState[$counter]==$State)
   {
      echo"The State capital is $StateCapital[$counter]";
   }
}
?>
</BODY>
</HTML>

in the states.php above inside the for loop i have a variable called $counter. There is also another for loop in the same page which also contains a variable called $counter. How does php know that these two variables are supposed to be different and not to replace the values within one with values from the other. Also when i click the submit page and go to capitals.php there is also a for loop with a variable called $counter. How does php know not to bring the $counter variable from the states.php page over to the capitals.php page and to not replace the values???

thanks

 
Old June 25th, 2004, 02:35 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

PHP actually does replace the value of counter in states.php. It just doesn't matter, because you re-initialize it in the for statement.

PHP does not carry values to other pages without submitting a form or reading a session/cookie, AFAIK. Besides, it does not matter because you re-initialize it again in the for statement in capitals.php.

HTH,

Snib

<><





Similar Threads
Thread Thread Starter Forum Replies Last Post
php question, undefined variable benappease Beginning PHP 0 December 6th, 2007 02:35 PM
Very simple variable assignment question gegonut ADO.NET 2 May 3rd, 2007 11:34 AM
XSL Variable and/or Parameter Question ripple XSLT 9 September 1st, 2006 12:16 PM
Easy Question: Setting a variable to null Enoch Access 8 May 22nd, 2006 10:30 AM
Simple (for most) Variable Question clareE XSLT 2 December 31st, 2005 08:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.