Jump to content

foreach problems


gilbertsavier

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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