0

a newbie question!

I have set up some code to create an image with this url:

www.mywebpage.php?wc1=99&wc2=6&wc3=23

In a php page want to use the wc1, wc2 and wc3 variables from the url as inputs to a bar chart graphic

the code on the receiving webpage includes this line:

$datay=array($_REQUEST['wc1'], $_REQUEST['wc2'], $_REQUEST['wc3']);

and using the datay array I get a nice bar chart with three bars.

My problem is I want to create urls with any number of wc? variables, and then create an array with any number of bars in the resulting bar chart. The numbero f bars should be dynamically set by some other real-time process.

So I realise I need to embed this line of code:

$datay=array($_REQUEST['wc1'], $_REQUEST['wc2'], $_REQUEST['wc3']);

in a loop and add in variablles to the array one by one until they are all added (whatever number there are).

However, I am stuck at the first hurdle as I do not know how to add a variable to the array.

This code does not work:

$firstBit = $_REQUEST['wc1'];
$datay=array(firstBit, $_REQUEST['wc2'], $_REQUEST['wc3']);

3 Answers 3

1

You're just missing the $ from your variable name

 $datay=array($firstBit, $_REQUEST['wc2'], $_REQUEST['wc3']);
Sign up to request clarification or add additional context in comments.

Comments

1
foreach($_GET as $key=>$value){
    echo $key;
    echo "<br/>";
    echo $value;
    echo "<br/>";
}

You'll soon understand

Comments

0

In your request, pass the values thus:

www.mywebpage.php?wc[]=99&wc[]=6&wc[]=23

And then you have an array out of the box...

$myArray = $_REQUEST['wc'];

1 Comment

@Dean it also means you don't need to change the code when you add the forth and fifth value and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.