Jump to content

[SOLVED] Where to go?


czukoman20

Recommended Posts

Hi all, I am working on a project that uses checkboxes to select all or some of the 50 states.

I was wondering if there was an easy route to making them a variable that would be like.

 

F_FP_$state  and then that would show all the states they selected and nix all the states they didn't select.

 

Examples of what i have already.

<?php
<input type="checkbox"  name="AL[0]" id="list" value="AL" />
// That repeated 50 times with different state values.
// When the user submits the checkboxes
$AL =$_POST['AL']; foreach ($AL as $st_1){}
// That repeated as well for each state.
?>

Link to comment
https://forums.phpfreaks.com/topic/164242-solved-where-to-go/
Share on other sites

Thanks, But for some reason when i did that.. it only echo's the last state that I selected.

<?php
<input type="checkbox"  name="states[0]" id="list" value="AL" />
<input type="checkbox" name="states[0]" id="list" value="HI" />
<input type="checkbox" name="states0]" id="list" value="MA" />
<input type="checkbox" name="states[0]" id="list" value="NM" />
// output
$states =$_POST['states']; foreach ($states as $state){ echo "$state"; }

// it echos NM when those 4 are selected?
?> 

 

also the twist to this is.. there are categories.. so each state needs its own Category Information

F_ = Financial

FP_ = Subcategory of Financial

So those need to be F_FP_$state But it needs to repeat itself like that for however many states are selected.. If they didn't select  a state I dont want the database to have a bunch of blank  "F_FP_  "

 

Thanks for the help so far

Link to comment
https://forums.phpfreaks.com/topic/164242-solved-where-to-go/#findComment-866397
Share on other sites

don't put a 0 in the square brackets. but using a 0, you are telling them to all use the same index of 0, with empty backets it will anonymously assign indexes

 

let's start with that before getting into the categories...if you get rid of the 0 does it work as you would expect?

Link to comment
https://forums.phpfreaks.com/topic/164242-solved-where-to-go/#findComment-866403
Share on other sites

Yes it does.

Now the output shows

ALHINAMH

thanks

 

Cool

Now for the categories... It wouldn't be as hard, but the page changes according to what the input in the url is..

Here is what i have so far

<?php
if ($cat1 == "FP_"){
$input = "F_FP_$state";
}
// of course that doesn't work lol 
?>
I'm thinking array, but idunno how to do that.

Link to comment
https://forums.phpfreaks.com/topic/164242-solved-where-to-go/#findComment-866418
Share on other sites

interesting

the output is now

 

F_FP_AL F_FP_AL ,F_FP_HI F_FP_AL ,F_FP_HI ,F_FP_MA F_FP_AL ,F_FP_HI ,F_FP_MA ,F_FP_NM

 

Wierd, I bolded the States to make it easier to read

 

The code I am using is

 

<?php
<input type="checkbox"  name="states[]" id="list" value="AL" />
<input type="checkbox" name="states[]" id="list" value="HI" />
<input type="checkbox" name="states[]" id="list" value="MA" />
<input type="checkbox" name="states[]" id="list" value="NM" />

//output 

$states =$_POST['states'];
if ($cat1 == "FP_"){
  $input = array();
  foreach($states as $state){
    $input[] = "F_FP_$state ";
echo implode(',',$input);
  }
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/164242-solved-where-to-go/#findComment-866478
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.