2010-02-10 15 views
5

to moja forloop który ma numer zbiorczego danychjak otrzymać wartość post dynamicznym polu tekstowym

$a = 1; 
for($i = 0; $i < sizeof($StudName); $i++) { ?> 
<tr align="left"> 
    <td class="table_label"><? echo $code[$i].' - '.$StudName[$i]; ?></td> 
    <td><input type="text" name="mark1<?= $a ?>" id="mark1<?= $a ?>" ></td> 
    <td><input type="text" name="mark2<?= $a ?>" id="mark2<?= $a ?>" ></td> 
    <td><input type="text" name="mark3<?= $a ?>" id="mark3<?= $a ?>" onkeyup="return percent('mark1<?= $a ?>','mark2<?= $a ?>','mark3<?= $a ?>','total<?= $a ?>','Average<?= $a ?>')" ></td> 
    <td><input type="text" name="total<?= $a ?>" id="total<?= $a ?>" onkeyup="return percent('mark1<?= $a ?>','mark2<?= $a ?>','mark3<?= $a ?>','total<?= $a ?>','Average<?= $a ?>')"></td> 
    <td><input type = "text" name="Average<?= $a ?>" id="Average<?= $a ?>" ></td> 
</tr> 
<? $a++; } ?> 

otrzymałem wartości tak:

function Addmark() { 

    echo "ssssssssssss"; 

    for($a = 1; $a <= $rowcount; $a++) { 
     $markI = 'mark1'.$a; 
     $markII = 'mark2'.$a; 
     $markIII = 'mark3'.$a; 
     $total = 'total'.$a; 
     $avg  = 'Average'.$a; 

     echo $mI[] = $this->input->post($mark1); 
     $mII[]  = $this->input->post($mark2); 
     $mIII[] = $this->input->post($mark3); 
     $Total[] = $this->input->post($total); 
     $Avrg[] = $this->input->post($Average); 
    } 

    $res = $this->staffModel->Addmark($mI, $mII, $mIII, $Total, $Avrg); 

    if($res == true) { 
     $this->session->set_flashdata('response', 'data added successfully !'); 
    } else { 
     $this->session->set_flashdata('response', 'data already exist !'); 
    } 

    $this->load->view('Sstudentlist',$data); 
} 

jest to poprawna składnia

Odpowiedz

1

Przede wszystkim upewnij się, że utworzyłeś tag form przed pętlą:

echo '<form name="frm" method="post" action="your-action-here">'; 

// now your loop that creates fields 
for(....) 
{ 
    echo '<input type="text" name="mark[]" value="'.$your_var.'" />'; 
} 

// now we specify the closing `form` tag 
echo '</form>'; 

//Now you can get the values of dynamically generated page like this in the page which you have specified in the `action attribute` of the form tag above: 

$_POST['mark']; 
// or you can see what it has got: 
print_r($_POST['mark']); 
Powiązane problemy