Jump to content

Recommended Posts

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

?>

Link to comment
https://forums.phpfreaks.com/topic/109452-php-loop-variables-please-help/
Share on other sites

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'];

 

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

 

 

 

 

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;
?>

 

 

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.