jwk811 Posted February 9, 2007 Share Posted February 9, 2007 i have several checkboxes and i get it by doing foreach($check as $c){ echo $c . ', ';} but how can i make that entire thing put into one variable? Link to comment https://forums.phpfreaks.com/topic/37817-checkbox-with-foreach-how-can-i-put-it-together-into-a-variable/ Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 are you looking for http://php.net/implode or http://php.net/explode ? Link to comment https://forums.phpfreaks.com/topic/37817-checkbox-with-foreach-how-can-i-put-it-together-into-a-variable/#findComment-180959 Share on other sites More sharing options...
kenrbnsn Posted February 9, 2007 Share Posted February 9, 2007 Do you want all the values from the $check array to be in a comma separated list as the value of a variable? If so, do it this way: <?php $csv_var = implode(',',$check); ?> Ken Link to comment https://forums.phpfreaks.com/topic/37817-checkbox-with-foreach-how-can-i-put-it-together-into-a-variable/#findComment-180960 Share on other sites More sharing options...
jwk811 Posted February 9, 2007 Author Share Posted February 9, 2007 no i already figured that out now i need to get that data which will have all of the checked areas separated by commas, i need that to go into my db as a text or varchar.. do you know what i mean? Link to comment https://forums.phpfreaks.com/topic/37817-checkbox-with-foreach-how-can-i-put-it-together-into-a-variable/#findComment-180988 Share on other sites More sharing options...
JJohnsenDK Posted February 9, 2007 Share Posted February 9, 2007 use insert query to update your database: $sql = mysql_query("INSERT INTO table_name SET text = '$check'"); Link to comment https://forums.phpfreaks.com/topic/37817-checkbox-with-foreach-how-can-i-put-it-together-into-a-variable/#findComment-180996 Share on other sites More sharing options...
jwk811 Posted February 9, 2007 Author Share Posted February 9, 2007 yeah but check only has the last option they picked.. im usually the foreach function to get them all but dont know how to put it into my database like that.. understand? Link to comment https://forums.phpfreaks.com/topic/37817-checkbox-with-foreach-how-can-i-put-it-together-into-a-variable/#findComment-181002 Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 If you already know how to implode the checkboxes into one variable, what don't you get? $check = implode(',', $check); $sql = mysql_query("INSERT INTO table_name SET text = '$check'"); Link to comment https://forums.phpfreaks.com/topic/37817-checkbox-with-foreach-how-can-i-put-it-together-into-a-variable/#findComment-181008 Share on other sites More sharing options...
JJohnsenDK Posted February 9, 2007 Share Posted February 9, 2007 if you dont understand our examples i think you should read more about the implode function. what jesirose wrote should do the trick, ohterwise you aint explaning your request good enough... Link to comment https://forums.phpfreaks.com/topic/37817-checkbox-with-foreach-how-can-i-put-it-together-into-a-variable/#findComment-181035 Share on other sites More sharing options...
jwk811 Posted February 9, 2007 Author Share Posted February 9, 2007 oh implode will take all the checkboxes that were used? oh i see now.. i thought that the implode thing was only for the commas.. thanks ill look into that Link to comment https://forums.phpfreaks.com/topic/37817-checkbox-with-foreach-how-can-i-put-it-together-into-a-variable/#findComment-181097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.