Forum Moderators: coopster
function serializer() {
$serialarray = array("radiostations", "hobbiesinterests"); //get serialized entries from MySQL db
$x = count($serialarray);
for ($i = 0; $i < $x; $i++) {
$genvar = unserialize($serialarray[$i]);
foreach($genvar[$i] as $key[$i] => $value[$i]);
//Print value of each array in their respective spot, by calling respective $variable
$variableArray[$i] .= $value.', ';
}
} 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
<?php
// Database Connection
include ("../includes/dbconnect.php");
// View link details
if($_GET['action']=="view"){
$id = $_GET['id'];
$getsurveysdetail = mysql_query("select * from survey WHERE id=$id");
while($row = mysql_fetch_array($getsurveysdetail))
{
extract($row);
$radio = unserialize($radiostations);
foreach($radio as $key => $value) {
$radioArray .= $value.', ';
}
print ("<div id=\"results\">
<p class=\"result_header\">Demographics</p>
<strong>Name:</strong> $name<br />
<strong>Date Submitted:</strong> $date<br />
<strong>Time Submitted:</strong> $time<br />
<strong>Email Address:</strong> $email<br />
<strong>Contact Number:</strong> $contactnumber<br />
<strong>Age:</strong> $age<br />
<strong>Marital Status:</strong> $maritalstatus<br />
<strong>Gender:</strong> $gender<br />
<strong>Lives:</strong> $live<br />
<strong>Works:</strong> $work<br />
<strong>Radio Stations:</strong> " . $radioArray . "<br />
Hope you understand this post...
[edited by: coopster at 2:15 pm (utc) on May 31, 2006]
[edit reason] inserted code, removed urls [/edit]
Regarding your question, i'm afraid i don't fully understand your problem.
Coopster
The reason being, is that I have 7/8 checkboxes that I have serialized. That makes 14 or so extra lines of code. I was thinking there must be away that I can create a function that will unserialize all the checkboxes into an array, and then i can just print each array using a single print statement per checkbox.
Does that make sense...
$myData['radiostations'] = $_POST['radiostations'];
$myData['hobbiesinterests'] = $_POST['hobbiesinterests'];
serialize($myData);