[PHP] Re: incrementing a register global
Thanks for all the suggestions. I am going to plan on trying them out just to see some other ways of making it work. I finally got it to work after hours of just playing around with the code. Here is what I ended up doing: for($i=1;$i<=$boxes;$i++){ echo $_GET['name'.$i]; } Moving the $i inside the bracket but not inside the single quote seem to make things happy. Thanks, Aaron -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: incrementing a register global
Just so there is no confusion...I mistyped the line: $names = substr(strrchr($_SERVER['QUERY_STRING'],"&"),7,1); It should be a 5 instead of a 7 at the end: $names = substr(strrchr($_SERVER['QUERY_STRING'],"&"),5,1); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: incrementing a register global
Aaron Todd wrote: > I am posting data to a php script. I have several variables that are the > same except the number at the end is different. So the url of the called > script will be something like: > > http://www.something.com/test.php?name1=Sam&name2=Bill&name3=Joe > > On my script I am using substr() and strrchr() to get the number of last > variable: > > $names = substr(strrchr($_SERVER['QUERY_STRING'],"&"),7,1); > > I am then trying to run a loop to call each variable and just print it on > the screen: > > for($i=1;$i<=$boxes;$i++){ > echo $_GET['name'].$i; > } did you tried foreach() with $_GET ( or $_REQUEST ) ? foreach ( $_GET as $key => $var ) { echo $key . ' => ' . $var; } but this is not "incrementing a register global" but 'accessing a superglobale array' -- Sebastian Mendel www.sebastianmendel.de www.sf.net/projects/phpdatetime | www.sf.net/projects/phptimesheet -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php