| | |
Keeping track of the checkboxes selected acrros the page
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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 :
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
This are the page buttons.Of course there is a for there somewhere,but I only want to include the important part
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)
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
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['sel'] , 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['sel']
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 )
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 :
PHP Syntax (Toggle Plain Text)
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; }
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
PHP Syntax (Toggle Plain Text)
<input type="button" value="<?=$k;?>" onclick="check();">
PHP Syntax (Toggle Plain Text)
$_SESSION['sel'].=$_GET['arr'];
PHP Syntax (Toggle Plain Text)
<form action="mail.php" method="post" name="form1">
PHP Syntax (Toggle Plain Text)
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'; ?> />
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['sel'] , 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['sel']
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 )
"Get rich or die tryin"(50-cent)
![]() |
Similar Threads
- How to get the link that was clicked even after the page gets refreshed (JSP)
- ASP.NET: Track IP Address (ASP.NET)
- Binary File IO (C#)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Keeping track of development knowledge (Computer Science)
- Checkboxes array (ASP)
- How to pre-select checkboxes in form? (PHP)
- Count number of checkboxes being checked in asp.net (ASP)
Other Threads in the PHP Forum
- Previous Thread: Autoresponder when submit form
- Next Thread: phpinfo page has array errors. What for?
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary body broken cakephp checkbox class cms code cron curl database date date/time directory display download dynamic echo email error file files folder form forms function functions global google href htaccess html image include insert integration ip java javascript joomla limit link list login loop mail menu mlm mod_rewrite msqli_multi_query multiple mycodeisbad mysql oop parameter paypal pdf php problem query radio random recourse recursion regex registrationform remote script search seo server sessions sms soap source space sql static syntax system table tutorial update upload url validation validator variable video web webdesign wordpress xml youtube





