bobe Posted June 9, 2008 Share Posted June 9, 2008 hi am in need of some help for one of my online forms. i need to use the GET_['???'] and use it in a loops somehow. this is what i want to get replace ? with increasing number $stone? = GET_['stone?']; my current code that does not work-someone please help <? //// get stone info from url using a loop with snum as the max amount of stones $min_stonez=1; $max_stones=$snum; $loopcounter = $min_stonez; do { $currentstone= "stone".$loopcounter; "\$stone".$loopcounter=$_GET['$currentstone']; $loopcounter++; }while ($loopcounter <= $max_stones); //// end loop ?> Quote Link to comment https://forums.phpfreaks.com/topic/109452-php-loop-variables-please-help/ Share on other sites More sharing options...
.josh Posted June 9, 2008 Share Posted June 9, 2008 I can't understand what you're trying to do in your loop, nor exactly what you're trying to do from your explanation...You're going to have to at least be a bit more clear in what you're trying to do... if you have a url like say http://www.blah.com/index.php?stone=4 you can access that stone variable like so: // this will print 4 on the screen echo $_GET['stone']; Quote Link to comment https://forums.phpfreaks.com/topic/109452-php-loop-variables-please-help/#findComment-561407 Share on other sites More sharing options...
bobe Posted June 9, 2008 Author Share Posted June 9, 2008 this is what i have in my url http://www.????????.com/order.php?snum=3&stone1=diamond&stone2=ruby&stone3=emerald .....meaning i have a max of 3 stones stone1 2 3 etc or however many stones they choose from the page before will show up as = snum i want to have $stone1= GET_['stone1'] within the php so that i can use $stone(watever number it is) later on in my php page. i was just trying to use a loop to get and state the variable within my php code Quote Link to comment https://forums.phpfreaks.com/topic/109452-php-loop-variables-please-help/#findComment-561415 Share on other sites More sharing options...
.josh Posted June 9, 2008 Share Posted June 9, 2008 hmm...okay I'm still not really understanding what exactly your problem is...if you know ahead of time what your $_GET variables are, simply assign them to normal variables: $snum = $_GET['snum']; $stone1 = $_GET['stone1']; $stone2 = $_GET['stone2']; $stone3 = $_GET['stone3']; or you could do a loop like this: <?php foreach($_GET as $key => $var) { $$key = $var; } echo $stone1; ?> Quote Link to comment https://forums.phpfreaks.com/topic/109452-php-loop-variables-please-help/#findComment-561436 Share on other sites More sharing options...
bobe Posted June 9, 2008 Author Share Posted June 9, 2008 ok thanks that helped. i just used your for each code. i just didn't want to write all that code to get value from the url, cause there might be alot in the future i would not want to update my code all the time. but this way is much faster and writes the code according to what the user input in the previous form. haha thanks for your help. i know you probably didn't get what i'm saying but your help is much appreciated. everything works thanks again Quote Link to comment https://forums.phpfreaks.com/topic/109452-php-loop-variables-please-help/#findComment-561459 Share on other sites More sharing options...
DarkWater Posted June 9, 2008 Share Posted June 9, 2008 Wait wait wait. You're using a form? Why in the world would you use GET then? Use POST and make the element an array. Quote Link to comment https://forums.phpfreaks.com/topic/109452-php-loop-variables-please-help/#findComment-561466 Share on other sites More sharing options...
.josh Posted June 9, 2008 Share Posted June 9, 2008 Wait wait wait. You're using a form? Why in the world would you use GET then? Use POST and make the element an array. True, but the principle is still the same. just change it from $_GET to $_POST Quote Link to comment https://forums.phpfreaks.com/topic/109452-php-loop-variables-please-help/#findComment-561471 Share on other sites More sharing options...
DarkWater Posted June 9, 2008 Share Posted June 9, 2008 Wait wait wait. You're using a form? Why in the world would you use GET then? Use POST and make the element an array. True, but the principle is still the same. just change it from $_GET to $_POST Not if he makes the elements on the form into an array. It simplifies things a lot. Quote Link to comment https://forums.phpfreaks.com/topic/109452-php-loop-variables-please-help/#findComment-561473 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.