checkbox

Reply

Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

checkbox

 
0
  #1
Apr 2nd, 2009
hi
i want to insert a symbol between all the chek box value
eg:the value will be either 1 or 0.
  1. $tmp =$_REQUEST["check1"];
  2. $tmp .=$_REQUEST["check2"];
  3. $tmp .=$_REQUEST["check3"];

this how i have requested the value .in order to separate the values .i want to add some symbols(like comma)plz tell me how to do that..

example
1,0,1,0,0
the above output i am trying to attain.
Last edited by peter_budo; Apr 5th, 2009 at 5:22 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 802
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: checkbox

 
0
  #2
Apr 2nd, 2009
  1. $tmp =$_REQUEST["check1"];
  2. $tmp .= ",". $_REQUEST["check2"];
  3. $tmp .= ",". $_REQUEST["check3"];

BTW, please use code tags.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: checkbox

 
0
  #3
Apr 2nd, 2009
if the user is not selecting all the check boxes .the out put is like this.
1,,,1,,,1,,,1,1,,1,1,,1,1,
i want it to be like if the user select it should contain the value.otherwise "0" should be placed
like 0,0,1,1,1
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: checkbox

 
1
  #4
Apr 2nd, 2009
Here's a possible solution.
Step 1, Create an empty array.
Step 2, Evaluate each checkbox in a loop. If empty, push a 0 into the array. Else, push a 1 into the array.
Step 3, Implode the array using a comma as the "string glue":
  1. <?php
  2. if(isset($_REQUEST["submit"])){
  3. $checkarray = array();
  4. $numCheckBoxes = 5; //number of checkboxes to evaluate
  5. for($i=1; $i<=$numCheckBoxes;$i++){
  6. if(empty($_REQUEST["check".$i])){
  7. array_push($checkarray,0);
  8. }else{
  9. array_push($checkarray,1);
  10. }
  11. }
  12. $checkstring = implode(",",$checkarray);//create comma separated string from array
  13. echo $checkstring;//outputs:1,0,1,1,0
  14. }
  15. ?>
This code assumes that the checkboxes are named check1,check2,check3,check4,check5...
Last edited by buddylee17; Apr 2nd, 2009 at 11:22 am.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: checkbox

 
0
  #5
Apr 7th, 2009
ya thanks its working.can u please tell me how to insert them. i want to discard the ,(commas) and insert the variables
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 164
Reputation: rm_daniweb is an unknown quantity at this point 
Solved Threads: 10
rm_daniweb rm_daniweb is offline Offline
Junior Poster

Re: checkbox

 
0
  #6
Apr 7th, 2009
echo RemoveComma($checkstring);

or just use.

$str = str_replace(',', '', $a); 

function RemoveComma($a) {
		 $str = str_replace(',', '', $a); 
		 return $str;
		 }
Last edited by rm_daniweb; Apr 7th, 2009 at 4:21 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: checkbox

 
0
  #7
Apr 7th, 2009
i want them to be stored in a array.should split
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 257
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: checkbox

 
0
  #8
Apr 7th, 2009
yes you can stored in a array easily. what do u mean by "should split" text
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: checkbox

 
0
  #9
Apr 7th, 2009
i want them to be stored in a array
a[0]=1;
a[1]=1;
a[2]=1;
something like this
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,524
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is online now Online
Posting Virtuoso

Re: checkbox

 
0
  #10
Apr 7th, 2009
The way I would do for performance and speed is as follows:
  1. $tmp =$_REQUEST["check1"];
  2. $tmp .=',' . $_REQUEST["check2"];
  3. $tmp .=',' . $_REQUEST["check3"];
  4. $tmp = str_replace(',,',',',$tmp);
  5.  
  6. //now to turn into an array
  7. $darray = explode(',',$tmp);
  8.  
  9. //now to display the array
  10. echo '<xmp>';
  11. print_r($darray);
  12. echo '</xmp>';
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC