friedice Posted October 4, 2010 Share Posted October 4, 2010 hello, um i got a form that stored an array of variables upon users clicks. it submits to another page fine as an array and i can print them using if(!empty($_POST['langSpoken'])) { echo "\n<p><strong>You selected the following LangSpoken:</strong></p>\n<ul>"; foreach($langSpoken as $lang) { // exclude any items with chars we don't want, just in case someone is playing if(!preg_match('/^[-A-Z0-9\., ]+$/iD', $lang)) continue; // print the lang echo "\n\t<li>" . htmlspecialchars($lang) . "</li>"; } echo "\n</ul>"; } else { echo "\n<p>No items selected</p>"; } it prints a list a of array like english spanish but i need to store each one in one variable so i can store in a database is there a way? thx Link to comment https://forums.phpfreaks.com/topic/215104-how-to-store-value-from-a-array-into-one-variable/ Share on other sites More sharing options...
trq Posted October 4, 2010 Share Posted October 4, 2010 Just loop through the array and store each value as you go. Link to comment https://forums.phpfreaks.com/topic/215104-how-to-store-value-from-a-array-into-one-variable/#findComment-1118813 Share on other sites More sharing options...
friedice Posted October 4, 2010 Author Share Posted October 4, 2010 can u show me how to? thanks so it will be like $languages = "english,spanish" Link to comment https://forums.phpfreaks.com/topic/215104-how-to-store-value-from-a-array-into-one-variable/#findComment-1118821 Share on other sites More sharing options...
trq Posted October 4, 2010 Share Posted October 4, 2010 You don't want to store all the values in one record within the database, that would be a poor design decision. Instead, each of these values should have there own row. You can then use another items 'id' to relate them if need be. Link to comment https://forums.phpfreaks.com/topic/215104-how-to-store-value-from-a-array-into-one-variable/#findComment-1118829 Share on other sites More sharing options...
friedice Posted October 4, 2010 Author Share Posted October 4, 2010 ahk thats a good point, how do u stored each in a seperated variable from a foreach loop? forgot how =.= thanks Link to comment https://forums.phpfreaks.com/topic/215104-how-to-store-value-from-a-array-into-one-variable/#findComment-1118840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.