I have a script that creates an array from a directory, then creates an option selection form. Once an option is selected, it goes to that directory.
What I would like to know is..
How is it possible to give ID's to the opions in the selection list and display it as
index.php?id=1
index.php?id=2
index.php?id=3
and so on...
Right now it is displayed as:
http://site.com/directory/selected option/
Any ideas?
Page ID?
Bump :queasy:
I saw this post when you first put it up and as I didn't understand it so I left it for a wiser man. I guess I wasn't the only that couldn't figure out what you need.
You said give id's to the options. Are you talking something like so
<select name="myselect">
<option id="option1" value="index.php?id=1">index.php?id=1
<option id="option2" value="index.php?id=2">index.php?id=2
<option id="option3" value="index.php?id=3">index.php?id=3
<select>
Not sure that there would be a purpose to doing it that way so I am guessing you are asking something else.
But then there is that dummy link which makes me think that you currently have
<option value="http://site.com/directory/option/">http://site.com/directory/option/
in the place of doing it like so
<option value="index.php?id=1">index.php?id=1
I which case it wasn't an id that your are looking for. Of course you could be asking how to set a variable to each option. But that isn't even clear.
We are going to need a bit more information. Maybe even a snippet of your code may help some.
Or maybe you are trying to set a variable to the "id=1"
if so
$optionvar = $_GET['id'];
Hmm..
Let me try and make it clearer.
This code gets the array and creates a selection for each item:
<form action="process.php" method="post">
<select name="item">
<?php
$results = str_replace(" ", " ", $results);
foreach ($results as $key => $value)
{
echo '<OPTION value='.$value.'> '.$value.'';
}
echo '</select>';
?>
</select>
<input type="submit" value="Git" />
</form>
As you see the action is to go to process.php, which redirects to the option selected:
<?php
$item = $_POST['item'];
?>
<h4>Loading....</h4>
<meta http-equiv="refresh" content="2;url=colors/<?php echo $item ?>" />
Now, lets say you selected blue, and were directed to that directory
It would show the URL as
www.site.com/colors/blue
I want to konw if it is possible to give this outcome:
index.php?page=1 [selected blue...]
index.php?page=2 [selected a different color...]
So if the user is redirected to www.site.com/colors/blue the actual page that needs to load is index.php?page=1.
If that is the case you need to look into mod rewrite.
I looked into it and it gave me the option to go from dynamic url to static url, but I want to do the opposite. Thanks for the help though.