[eluser]madkris[/eluser]
here's the modified script(note: i left some of the variables as they are to avoid confusion) of an example i got from the net:
Code:
var iterator = 1;
var uplTemplate = new Template('<div id="element-templates"><br><div id="#{id}" class="row"><div class="form-dropbox">#{label}: <select name="#{name}"> <option value="">Select Contest Problem</option><?php foreach($list->result_array() as $row){ echo "<option value=".$row['pcode'].">".$row['pcode']." -- ".$row['ptitle']."</option>";}?> </select></div></div></div>');
function insertNewTemplate(){
iterator++;
Element.insert($('files'),uplTemplate.evaluate({'id':'file' + iterator, 'name':'problem' + iterator, 'label':iterator}));
}
$('add-file-upload').observe('click',insertNewTemplate);
here's where i insert them to the database.
Code:
foreach($query->result_array() as $row) {
$num = $row['contestid'];
}
$sql = "INSERT INTO contestproblems
VALUES ($num, '$problem1')";
$this->db->query($sql);
if($problem2 != NULL){
$sql = "INSERT INTO contestproblems
VALUES ($num, '$problem2')";
$this->db->query($sql);
}
.
.
.
.
.
if($problem15 != NULL){
$sql = "INSERT INTO contestproblems
VALUES ($num, '$problem15')";
$this->db->query($sql);
}
not sure if making a loop will do the trick.
i know my code is very messy, do be gentle.. -.-