byronrode Posted May 31, 2006 Share Posted May 31, 2006 you can view it here[a href=\"http://devart.pastebin.com/748927\" target=\"_blank\"]serializer function[/a]basically what I have is a survey form that submits data to a database. Checkboxes have been serialized for easier validation.I am busy coding a backend for the survey, where I can retrieve the data in the database and display in a user friendly way for the client.I am able to recover all of the other data excepting the checkbox data.if i code each serialize loop individually, it works 100% but the 2 values mentioned in the above script are 2 of 20.I don't really want to have to type 4 lines of code for each one, so hence the decision to create the function.Now I have tested this function, and it is not returning any errors, so I would say it is complete to an extent, but how would I call an individual variable from within the function to print outside the function...Much like below[a href=\"http://devart.pastebin.com/748980\" target=\"_blank\"]How it should possibly render[/a]Hope you understand this post... Quote Link to comment https://forums.phpfreaks.com/topic/10859-function-help/ Share on other sites More sharing options...
poirot Posted May 31, 2006 Share Posted May 31, 2006 $radio = unserialize($radiostations);$radioArray = implode(', ', $value); Quote Link to comment https://forums.phpfreaks.com/topic/10859-function-help/#findComment-40587 Share on other sites More sharing options...
byronrode Posted May 31, 2006 Author Share Posted May 31, 2006 [!--quoteo(post=378734:date=May 31 2006, 05:10 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 31 2006, 05:10 PM) [snapback]378734[/snapback][/div][div class=\'quotemain\'][!--quotec--]$radio = unserialize($radiostations);$radioArray = implode(', ', $value);[/quote]Thanks for the reply, but that is not what i am looking at doing. I can do the above, but I want to be able to write a function that can handle an array of queries [code]$array('radiostations', 'hobbiesinterests');foreach($array as $key => $val)[/code]There is an example in my post. The first link... but that does not render an output. Quote Link to comment https://forums.phpfreaks.com/topic/10859-function-help/#findComment-40591 Share on other sites More sharing options...
poirot Posted May 31, 2006 Share Posted May 31, 2006 Sorry, but I can't understand what you mean with "handle an array of queries ".Do you want to use the values in a query, or do you already have the query's results and want to play with them and the array? Quote Link to comment https://forums.phpfreaks.com/topic/10859-function-help/#findComment-40595 Share on other sites More sharing options...
byronrode Posted June 1, 2006 Author Share Posted June 1, 2006 I'll explain...I have a survey form that submits data to a database. The checkbox data is serialized before being saved in the database.Now.I have a script that pulls the data from the database using variables. E.g.[code]Name: <?php print $name; ?>Radio Stations: <?php print $radioArray; ?>Hobbies and Interests: <?php print $hobbyArray; ?>[/code]At the moment I am unserializing each individual checkbox array with the following script[code]$radio = unserialize($radiostations);foreach($radio as $key => $value) {$radioArray .= $value.', ';}$hobby = unserialize($hobbiesinterests);foreach($hobby as $key => $value) {$hobbyArray .= $value.', ';}[/code]Now thats only for two of the 20 or so checkbox values. What I want to do is to write a function that will in effect unserialize all the checkbox values ($hobbiesinterests | $radiostations | $and | $others) and then take the unserialized data from each variable and pass it to an array.So lets say this.We call the array $unserialized[code]$unserialized[0] = //the unserialized content of $radiostations [5FM, East Coast Radio]$unserialized[1] = //the content of $hobbiesinterests [Golf, PHP]$unserialized[2] = // And so on[/code]so instead of writing 4 lines of code for every checkbox, i can write 4 lines for all the checkboxes in one, and then print them by calling there position in an array... Quote Link to comment https://forums.phpfreaks.com/topic/10859-function-help/#findComment-40819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.