gilbertsavier Posted June 25, 2009 Share Posted June 25, 2009 I have a list of names, emails, a checkbox and a message box, the names and emails are from a database. What I am trying to do to select say 5 of the names from the list via the checkbox and send an email to those who I have picked. I can't seem to get my head around the foreach function, is it that there has to be a foreach function to collect the email addresses and to see which user has been selected or do they come under the same one. I have tried to do some of the coding myself, but fear I am getting more and more confused, some help would be great. Here is what I have done so far. Thanks lokananth www.mioot.com Quote Link to comment https://forums.phpfreaks.com/topic/163616-foreach-problems/ Share on other sites More sharing options...
arimakidd Posted June 26, 2009 Share Posted June 26, 2009 I am a bit unclear as to the situation. You data is coming from a database or a form? If a form, then you have to loop through the elements and with each iteration run a "if" statement to see of the check box was checked and then store that value in an array. When the looping is done you have an array of all the names or emails as you say. You can even run a loop and create an array where the index or key is the name and the value is the email address. If your data is coming from a database then what ever query you are running you can then put it in an array and use the 'foreach' function. The statement: foreach($pieces as $value) { } Will iterate through the entire array. In other words, foreach is a loop and on each round or turn or iteration the value of the present index will be assigned to the variable "$value". So when this is run all the values of the array in the array variable "$pieces" will be assigned to $value. In more detail lets say you have an array with 3 items, the first letters of the alphabet and the array is assigned to the variable $alpha, like this: $alpha = array("a","b","c"); And you use the foreach on it like this: foreach($alpha as $value) { echo $value."<br>"; } Your output would be: a b c Hope this helps somewhat. Quote Link to comment https://forums.phpfreaks.com/topic/163616-foreach-problems/#findComment-864317 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.