| | |
checkbox
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
hi
i want to insert a symbol between all the chek box value
eg:the value will be either 1 or 0.
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.
i want to insert a symbol between all the chek box value
eg:the value will be either 1 or 0.
php Syntax (Toggle Plain Text)
$tmp =$_REQUEST["check1"]; $tmp .=$_REQUEST["check2"]; $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.
php Syntax (Toggle Plain Text)
$tmp =$_REQUEST["check1"]; $tmp .= ",". $_REQUEST["check2"]; $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. 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":
This code assumes that the checkboxes are named check1,check2,check3,check4,check5...
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":
php Syntax (Toggle Plain Text)
<?php if(isset($_REQUEST["submit"])){ $checkarray = array(); $numCheckBoxes = 5; //number of checkboxes to evaluate for($i=1; $i<=$numCheckBoxes;$i++){ if(empty($_REQUEST["check".$i])){ array_push($checkarray,0); }else{ array_push($checkarray,1); } } $checkstring = implode(",",$checkarray);//create comma separated string from array echo $checkstring;//outputs:1,0,1,1,0 } ?>
Last edited by buddylee17; Apr 2nd, 2009 at 11:22 am.
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
•
•
Join Date: Jan 2007
Posts: 164
Reputation:
Solved Threads: 10
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.
•
•
Join Date: Apr 2009
Posts: 257
Reputation:
Solved Threads: 37
yes you can stored in a array easily. what do u mean by "should split" text
The way I would do for performance and speed is as follows:
php Syntax (Toggle Plain Text)
$tmp =$_REQUEST["check1"]; $tmp .=',' . $_REQUEST["check2"]; $tmp .=',' . $_REQUEST["check3"]; $tmp = str_replace(',,',',',$tmp); //now to turn into an array $darray = explode(',',$tmp); //now to display the array echo '<xmp>'; print_r($darray); echo '</xmp>';
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
![]() |
Similar Threads
- how do i get more than one checkbox being checked (ASP)
- checkbox values calculation with PHP (PHP)
- hide checkbox in grid appropriately (ASP.NET)
- recordset from multiple checkbox values (ASP)
- checkbox values (JSP)
- Adding a checkbox column dynamically (C#)
Other Threads in the PHP Forum
- Previous Thread: Drop down box problem
- Next Thread: Passing GET variable of previous page to present page
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image images include insert integration ip java javascript joomla ldap limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop open parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update upload url validation validator variable video web xml youtube






