Forum Moderators: coopster
I have a form with checkboxes on index.php. When submitting the form, MutliFunc.php is opened with the checked boxes appended as such: MultiFunc.php?FuncID=FuncID7&FuncID=FuncID21&submit=Go
The different FuncIDs refer to different functionalities that a product may have. The whole point of this page is for a user to view which products have the functionality he chosses on that form. In theors, there can be up to 75 different FuncIDs.
What I can't work out is how to read those FuncIDs from the URL on the page. I'm using DW, and Im quite new to PHP..
Thanks, Adam
[EDIT: I should have mentioned, I dont want to store the FuncIDs in the db]
Also, it literally pulls up the FuncID itself, how can I translate it to the name of the FuncID? As an example, FuncID6 is "Media Player", and the page should read: You filtered for Media Player, as opposed to: You filtered for FuncID6
Thanks again, Adam
foreach ( $_GET["FuncID"] as $func )
{
//do something with $func, which will contain the ID passed through the URL
}
Also, make sure in your form that all your checkboxes have names like name="FuncID[]".
Edit: The reason for this is that, from the looks of your current URL, the value of ALL the checkboxes is getting put into $_GET["FuncID"] one at a time, each one overwriting the last value.
[edited by: WesleyC at 6:32 pm (utc) on Aug. 2, 2007]
My code is as follows now:
<h1 class="title">You filtered for: </h1>
<?php foreach ( $_GET["FuncID"] as $func )
{
echo $_GET['FuncID'];
}
?>
and the browser shows:
You filtered for:
ArrayArray
I do have the checkboxes as name="FuncID[]". That form is created with php based on my db as such:
<form action="MultiFunc.php" method="get" name="m">
<?php do {?>
<input type="checkbox" name="FuncID[]" value="<?php echo $row_rsMenu['FuncID']?>"> <?php echo $row_rsMenu['name']?> <br />
<?php
} while ($row_rsMenu = mysql_fetch_assoc($rsMenu));
$rows = mysql_num_rows($rsMenu);
if($rows > 0) {
mysql_data_seek($rsMenu, 0);
$row_rsMenu = mysql_fetch_assoc($rsMenu);
}?>
<input name="submit" type="submit" value="Go" />
</form>
If I understand you correctly, it would be better to save the form entries in my db, is that correct?
By the way, the URL is now as such (due to the []):
MultiFunc.php?FuncID%5B%5D=FuncID26&FuncID%5B%5D=FuncID27&submit=Go
I'm not suggesting that you save the user's entry to the database (though that might come in handy in the future for statistical purposes), just that you save the information about the checkboxes there--which, now that I see your code, I know you're already doing. :)
Now, in order to figure out what the name of the selected checkboxes were, you can simply do another database query (possibly within the foreach statement) to pull the name of the checkbox out of the database based on the ID.
[edited by: WesleyC at 7:05 pm (utc) on Aug. 2, 2007]
so I have the echo $func in the foreach and thats fine, it returns the FuncIDs that are in the url. Is there a smiple way to format that, as right now it shows the as such:
FuncID1FuncID5FuncID6
I think Ill be able to call the FuncIDs in a new record set top "translate" them to normal names.
Thanks for your help so far!
EDIT: Never mind, I was able to format it with:
<?php foreach ( $_GET["FuncID"] as $func )
{
echo $func, ", \n";
}
?>
$func = str_replace("FuncID1", "Wireless email", $func);
$func = str_replace("FuncID5", "Camera", $func);
$func = str_replace("FuncID6", "BlackBerry Maps", $func);
$func = str_replace("FuncID7", "Media player", $func);
$func = str_replace("FuncID10", "MMS", $func);
$func = str_replace("FuncID11", "GPS", $func);
$func = str_replace("FuncID18", "Trackball", $func);
$func = str_replace("FuncID21", "Trackwheel", $func);
$func = str_replace("FuncID22", "3.5mm jack", $func);
$func = str_replace("FuncID26", "Built-in speakerphone", $func);
$func = str_replace("FuncID27", "Bluetooth technology", $func);
$func = str_replace("FuncID39", "MP3 ringtones", $func);
$func = str_replace("FuncID44", "microSD card", $func);
$func = str_replace("FuncID46", "RIM wireless modem", $func);
$func = str_replace("FuncID47", "Tethered modem capability", $func);
As you can see, Ive reduced the list of 74 functions to 15 to not overload the page, but the str_replace doesnt want to work. any ideas?
Thanks