07-15-2008, 09:06 PM
If I have a page:
and I need the options:
Where do I store those parameters?
07-15-2008, 09:36 PM
Where would you like them to be stored?
07-15-2008, 09:40 PM
YOU don't need to store them at all, PHP does that work for you. Anything after the '?' and separated by an & indicates a key=value pair thats stored in the _GET superglobal.
$price = 0.0;
if (isset($_GET['price']) || !empty($_GET['price'])
$price = (double)$_GET['price'];
This is how I would recommend retrieving values. Two things are important - the first is that it exists (isset($_GET['price'])) checks that, and the second is that its the correct data-type, I assumed that the price could be a double. Casting that will store the value as a double and corrupt the $price if it cannot be parsed (leaving you with 0.0). You're validation later can handle that.
But as I mentioned, you don't need to retrieve these at all, $_GET will still hold the value of price for the entire page load, and since its superglobal you can use it in the scope of a function call without passing the parameter in or needing to globalize the $price variable.
If you just support the 3 options (10, 20 & 30), I'd change the above. Instead of seeking for a double, I would seek for an int that is in that array:
$validPrice = array(10, 20, 30);
throw new Exception('Price is required!');
if (in_array((int)$_GET['price'], $validPrice))
// Do something since its valid
Does this answer you're question?
07-15-2008, 11:00 PM
Maybe you can take a look here. I have something else on this, but I explained what I needed better.
07-15-2008, 11:21 PM
This is really up to how you want to do it, but you simply need to use conditional checks on you're price variable.
die ('No price has been selected!');
echo "Here is the information about price 10!";
echo "Here is the information about price 20!";
echo "Here is the information about price 30!";
die('Invalid price specified');
I cannot really give you a whole pile of help on this since I am not familiar with you're scripts, requirements, or variable handling. All I can really offer is that you need to logically break you're pages up into what you need them to be, and specify you're calls with conditional checks - ifs or switches. Depending on the implementation, I cannot even guarantee that conditions are what you are looking for, it may be used for conditions as a part of a query.
I'm sorry, but without understanding what you are doing I cannot offer much other help.