chiefrokka Posted August 26, 2008 Share Posted August 26, 2008 I can figure it out with some for loops and what not, but just wondering if there's a function that does this for you already. I have 12 html list menu's that are INT's between 1-12 they can select... when they submit, I need to varify they didn't choose the same numbers for two different list menu's. basically I need the html form fields to be Unique. maybe there's a tag to add to the html form instead or is there a php function to test? Quote Link to comment https://forums.phpfreaks.com/topic/121470-comparing-_post-vars-so-no-duplicate/ Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 I assume that the checkboxes use the array naming convention for the data in order to make the name of the checkboxes a multidimensional array, correct? Then you can just use array_intersect. Quote Link to comment https://forums.phpfreaks.com/topic/121470-comparing-_post-vars-so-no-duplicate/#findComment-626415 Share on other sites More sharing options...
chiefrokka Posted August 26, 2008 Author Share Posted August 26, 2008 there not check boxes. there List/Menu(drop down) boxes with options to choose a number from 1-12 but they can't be the same. so their basically ranking each item from best to worst... 1-12 I'm naming them Pick1 Pick2 Pick3 etc. Quote Link to comment https://forums.phpfreaks.com/topic/121470-comparing-_post-vars-so-no-duplicate/#findComment-626420 Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Ha, woops, thought you said checkboxes. That's not how you should name them though. You should name them ALL 'pick[]', and then $_POST['pick'] will be a multidimensional array containing all the choices. You can then use array_unique, like this: if (!($_POST['pick'] === array_unique($_POST['pick'])) { //duplicate choices! } Quote Link to comment https://forums.phpfreaks.com/topic/121470-comparing-_post-vars-so-no-duplicate/#findComment-626422 Share on other sites More sharing options...
chiefrokka Posted August 26, 2008 Author Share Posted August 26, 2008 your right, I should probably be using array's for this crap. I keep forgetting to use arrays, maybe because I'm not too familiar with them yet. thanks "The array_unique() function removes duplicate values from an array. If two or more array values are the same, the first appearance will be kept and the other will be removed." I don't want to remove them though but I just want to check if duplicates exist so i can prompt the user to go back and fix their choices. Quote Link to comment https://forums.phpfreaks.com/topic/121470-comparing-_post-vars-so-no-duplicate/#findComment-626431 Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Trust me on this one. It's not overwriting your array, it's comparing the normal array with the truncated one. If they're the same, there were no duplicates. Quote Link to comment https://forums.phpfreaks.com/topic/121470-comparing-_post-vars-so-no-duplicate/#findComment-626433 Share on other sites More sharing options...
chiefrokka Posted August 27, 2008 Author Share Posted August 27, 2008 I'm playing with multi arrays for first time and have a question now. I have an array set up that print_r works just fine so I store their ranks from the html form properly... they have 12 TeamNames they have to rank from best to worst. The TeamName is defined already by me. $Team[1][TeamName][Rank] $Team[2][TeamName][Rank] $Team[3][TeamName][Rank] so when they fill out the html form the only thing their choosing is the rank. so my array could be like this based on their ranks they chose. $Team[1][Patriots][2] $Team[2][Colts][1] $Team[2][Cowboys][3] How do I echo let's say the [TeamName] based on a for loop for the [Rank]. I also need to know how to loop through all 12 ranks and update my database with that TeamName <?php for ($i=1; $i<=12; $i++) { echo "<br>Rank #".$i." = ".$Team["Rank"=$i].""; // How do I grab their #1 ranked team? // Rank #1 = TeamName // Rank #2 = TeamName $str= "Rank_".$i.""; // variable name in database = Rank_1, Rank_2, etc. // how do I update database for that TeamName mysql_query("UPDATE `Users` SET `$str` = '".$Team[$i]["Team"]."', Already_Picked='1' Where `Name` = '$user' ") or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/121470-comparing-_post-vars-so-no-duplicate/#findComment-626517 Share on other sites More sharing options...
True`Logic Posted August 27, 2008 Share Posted August 27, 2008 that would be easier to do with a javascript onsubmit() clause rather than php validation, it is easy to do with php, but a far excess and unneccessary waste of time and effort, onsubmit you need to check if document.getElementById('pickN').value is the same as picknn etc.... you can do that quite quickly with a loop and then document.location.href if it passes the validation -T`L Quote Link to comment https://forums.phpfreaks.com/topic/121470-comparing-_post-vars-so-no-duplicate/#findComment-626630 Share on other sites More sharing options...
chiefrokka Posted August 27, 2008 Author Share Posted August 27, 2008 I don't know java so I'd rather do it all in php. there's gotta be a way to search your multi array and grab a value based on a certain criteria (rank) Quote Link to comment https://forums.phpfreaks.com/topic/121470-comparing-_post-vars-so-no-duplicate/#findComment-626780 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.