I have two while statements that pull in two comma separated lists. One of the lists is actual html code that generates form fields. The other list are the labels for the form fields, customized by user input. Since both arrays are looping separately, I am unable to place the relevant label next to its form field.
The form fields and labels will always match. Here is the code so far. I don't expect to get an answer straight away, but would like to start the dialogue. Thanks!
Code: Select all
//Retrieve storyID from home page hyperlink
$storyID = $_GET['storyID'];
//Database details
//Get form field IDs from the_story table, based on storyID
$formFields = mysql_query("
SELECT story_fields
FROM the_story
WHERE ID = $storyID
");
while($rowField = mysql_fetch_array($formFields))
{
//$myFields returns comma separated form field IDs (1,2,3,4,etc.)
$myFields = $rowField['story_fields'];
}
//Parse form fields into separate values and associate with actual HTML from form_fields table
$arrField = explode(",",$myFields);
foreach($arrField as $f)
{
$singleField = trim($f);
$placeField = mysql_query("
SELECT field_html
FROM form_fields
WHERE ID = $singleField
");
while($rowField = mysql_fetch_array($placeField))
{
//echo individual form field html
echo $rowField['field_html'];
echo "</br>";
}
}
//Get form field labels based on storyID
$formLabels = mysql_query("
SELECT field_labels
FROM the_story
WHERE ID = $storyID
");
while($rowLabel = mysql_fetch_array($formLabels))
{
$myLabels = $rowLabel['field_labels'];
}
//Parse form field labels
$labels = $myLabels;
$arrLabel = explode(",",$labels);
foreach($arrLabel as $l)
{
$newLabel = trim($l);
echo $newLabel;
echo "</br>";
}
http://www.brendonbarnett.com/temp/MyStory/test.html