I have asked a similar question but the answers didn't really help me in solving or think of a solution.
I have my JS script upload a file (using PHP as its callback) then take the data from the upload.php and reformat it using the JS code snippet below to show the user the inputs.
When the data is presented to the user it looks like this as an example:
input type="text" class="r" name="scene" value="1" />
<input type="text" class="r" name="int_ext" value="INT" />
<input type="text" class="r" name="scene_desc" value="Bedroom" />
<input type="text" class="r" name="day_night" value="DAY" />
<input type="text" class="r" name="scene" value="2" />
<input type="text" class="r" name="int_ext" value="EXT" />
<input type="text" class="r" name="scene_desc" value="Outside" />
<input type="text" class="r" name="day_night" value="DAY" />
<input type="text" class="r" name="scene" value="3" />
<input type="text" class="r" name="int_ext" value="INT" />
<input type="text" class="r" name="scene_desc" value="Bedroom" />
<input type="text" class="r" name="day_night" value="DAY" />
<input type="text" class="r" name="scene" value="4" />
<input type="text" class="r" name="int_ext" value="EXT" />
<input type="text" class="r" name="scene_desc" value="Bedroom" />
<input type="text" class="r" name="day_night" value="NIGHT" />
...
this output can range from 100 to 400 sets of inputs. One set is grouped into 4 inputs.
I'm trying to have each dynamic set fit into a query like this
mysql_query("INSERT INTO (`project_id`, `scene_number`, `int_ext`, `scene_description`, `day_night`) VALUES (10, '{$scene_num}', '{$int_ext}', '{$scene_desc}', '{$day_night}')");
Before anyone points out, In my code I am filtering and cleaning the inputs before inserting them into the database
My problem is I can't be creative enough to insert each scene information into the database like I envision it.
In my PHP code I echo out the line:
if(!$word)
return NULL;
if(preg_match_all($pattern, $contents, $matches))
{
foreach($matches as $match) {
$list = "<li><div class='int'>".implode("</div></li><li><div class='int'>", $match)."</div></li>\n";
}
}else{
$list = "No matches found";
}
In my JS code I split out the line and divide it into the 4 inputs:
$int.html(function(i, html) {
return html.replace(/(\d+)(.+)/,function(str,s1,s2){
var text = s2.split('.');
var text2 = text[1].split('-');
var text3 = text2[1].split(' ');
return '<input class="r" name="scene" value="'+ s1.replace(/^\s*/, '').replace(/\s*$/, '') +'" />' +
'<input class="r" name="int_ext" value="'+ text[0].replace(/^\s*/, '').replace(/\s*$/, '') +'" />' +
'<input class="r" name="scene_desc" value="'+ text2[0].replace(/^\s*/, '').replace(/\s*$/, '') +'" />' +
'<input class="r" name="day_night" value="'+ text3[1].replace(/^\s*/, '').replace(/\s*$/, '') +'" />';
});
});
I'm trying to form an AJAX request to send the values to a PHP page for processing, I'm not sure how to grab the data I need and send it off via AJAX (I know how to perform AJAX request, but in this case I don't know how to grab a dynamic number of inputs to be processed).
Any tips?