Jump to content

Recommended Posts

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...
Link to comment
https://forums.phpfreaks.com/topic/10859-function-help/
Share on other sites

[!--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.
Link to comment
https://forums.phpfreaks.com/topic/10859-function-help/#findComment-40591
Share on other sites

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...
Link to comment
https://forums.phpfreaks.com/topic/10859-function-help/#findComment-40819
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.