Eko 1 Junior Poster in Training

I have a list of users(signed for a newsletter).I'm retrieving the list from a database when the admin clicks on a button.
There are maximum 10 users diplayed per page.For example,if I had 30 users in the database,I would have 3 pages of users(Page 1,2,3);
For each listed user ,I have a checkbox on the right side.The checkbox is for when the admin wants to selected a few people to whom send the newsletter.
Ex:
Page: 1|2|3
1.ana checkbox
2.john checkbox
3.mike checkbox
---------------------
10.cindy checkbox
Then,if the admin want to go to another page :
Page : 1|2|3
1.lucy checkbox
2.shinoda checkbox
-------------------------
10.michelle checkbox
and so on
Down this list of users , the admin has 2 button : Send and Sendall
The Send button is used when he wants to send the newsletter only to the people with the checkbox selected

My problem is when the admin wants to select people from different pages(Ex: he selects 2 people from the first page,3 on the second ,1 person on the last page , and then he clicks send)
Because when he clicks the button for another page,the data is lost,so it's hard to keep evidence of the total checkboxes selected
Here is what I got so far :

function check(){    
                    var i;
                    var total;
                    var mail='';
                    for(var i=0; i < document.form1.mail.length; i++)
                    {
                        if(document.form1.mail[i].checked)
                        {
                            mail+=document.form1.mail[i].value+',';
                        }
                    }                window.location='admin.php?page=<?=$k;?>&action=mail&arr='+mail;
                }

This is my javascript function I use on the Page buttons
Notice The window.location on the end.This is how the admin browse through the list.The arr variable contains a string with the id of each selected user

<input type="button" value="<?=$k;?>" onclick="check();">

This are the page buttons.Of course there is a for there somewhere,but I only want to include the important part

$_SESSION['sel'].=$_GET['arr'];

When the user clicks the button , the page reloads and to keep the mail string while the admin browse trough the pages, I store it in a session(I don't know if this is the best solution)

<form action="mail.php" method="post" name="form1">

This is for the 2 send buttons(Send and Sendall).The form goes to a different page where it sends mail to the selected users

while($row=mysql_fetch_array($result))
    $v=explode(',',$_SESSION['sel']);
                                    print_r($v);
                                    $bool=0;
                                    for ($i=0;$i<strlen($v);$i++){
                                        if ($v[$i]==$row['id'])
                                        {
                                            $bool=1;
                                        }
 <input type="checkbox" name="mail" value="<?=$row['id'];?>" <?php if ($bool==1) echo 'checked'; ?> />

Oki,here I'm taking the string containing all the id's of the selected checkboxex and store it in an array,so I have the checkbox selected when the user comes from page 2 to page 1
I do this with a simple if statement.
This are the checkboxes.Each has the value , the user id in the database;

In the mail page,I'm also using the explode function to the $SESSION , and on the array resulted from this ,I'm running the array_unique() function(because everytime the user click on a page,the previous selected checkboxes are again inserted into the $SESSION

This is a very poor programming solution to solve the problem(I'm aware of that) , so I'm asking if u ladies/gentlemens know a better solution(if you been trough this kind of problem and found a good way of doing it )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.