PattyB Posted September 14, 2006 Share Posted September 14, 2006 This code takes an array from some user input and matches it to an array stored in a field in a database. The first foreach should loop through each value from the user input. The second foreach should take the value from the first foreach and match it to each value in the database. I cannot get the outside foreach to loop through. Ex: User selects 1,2, and 3. The code will only process 1 and not 2 or 3.Here is what the ouput looks like:No Match Groups from database:2User-selected:1Match Groups from database:1User-selected:1No Match Groups from database:3User-selected:1Here is what the code looks like:[code]<?php$sql = "SELECT * FROM members"; //Set parameter for query $results = mysql_query($sql); //Get data from database $groups_input_parsed = unserialize($groups_input); //Parse Mail Form and store foreach($groups_input_parsed as $list_group) //Roll through each selected checkbox{ while ($row = mysql_fetch_array($results)) //Roll through each row in member database { $id = $row["id"]; //Store ID $email = $row["email"]; //Store Email $groups=unserialize($row["groups"]); //Parse Group array foreach($groups as $groups1) //Roll through group database { if ($groups1 == $list_group) // If member group is equal to selected group { printf("<p><b>Match</b> <br>"); //Do Stuff Here printf("Groups from database:"); echo $groups1; printf("<p> User-selected:"); echo $list_group; } //end if else //Otherwise there are no matches { printf("<p><b>No Match</b> <br>"); //Do Stuff Here printf("Groups from database:"); echo $groups1; printf("<p> User-selected:"); echo $list_group; } //End else } //End Inside foreach } //End While } //end outside foreach?>[/code]This probably isn't the best way to it but I am new to php. Quote Link to comment https://forums.phpfreaks.com/topic/20761-help-with-some-code-not-working/ Share on other sites More sharing options...
HuggieBear Posted September 14, 2006 Share Posted September 14, 2006 Try putting the [code=php:0]$results = mysql_query($sql); [/code] Inside the foreach loop.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/20761-help-with-some-code-not-working/#findComment-91928 Share on other sites More sharing options...
PattyB Posted September 14, 2006 Author Share Posted September 14, 2006 Yup that was it. Thanks so much! :) Quote Link to comment https://forums.phpfreaks.com/topic/20761-help-with-some-code-not-working/#findComment-91972 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.