dimanche 20 avril 2014

PHP - Foreach can't recognize the ID


Vote count:

0




i'm trying to create an script to update multiple rows.


To do that, i created one html table, with all the values from one specific database table.


And i inserted in each html row, one checkbox to check, and submit.


After submit, all the checked rows values appears inside textboxes, like this:


http://ift.tt/1lq6SEt


And the user just need to edit the checkboxes and save.


The problem is that, i'm doing this project using MVC, and my Script only works if i insert the post inside the foreach, like this:



function confirmedit($checkbox, $editcheckbox, $u_job_name, $checkedit, $savecheck){

if (is_array($savecheck)) {

foreach ($savecheck as $id){

$u_job_name = $_POST['u_job_name'][$id];

$save_jo = "UPDATE job_offers SET job_name ='".$u_job_name."' WHERE job_id = '".$id."' ";

$array = db_query($save_jo, '+');


echo '<pre>';
echo $save_jo;
echo '</pre>';

}

}

}


But i'm doing this project in MVC, and i can't put POST's inside the model.


So i decided to put the POST's inside the controller:



if(isset($_POST['save']) && !empty($_POST['savecheck'])){

$countChecksave = count($_POST['savecheck']);
$savecheck = $_POST['savecheck'];
$checkedit = $_POST['checkedit'];

foreach ($savecheck as $id){

$u_job_name = $_POST['u_job_name'][$id];

}
}else{

$u_job_name = NULL;
}


Resuming, my query is inside a foreach on Model, and the POST is inside the controller.


But it doesn't work because he can't recognize the ID from the textbox, i updated three rows and i written 1, 2, 3 on each textbox, i did an echo to my Query, and my query is doing that:



UPDATE job_offers SET job_name ='3' WHERE job_id = '186'
UPDATE job_offers SET job_name ='3' WHERE job_id = '188'
UPDATE job_offers SET job_name ='3' WHERE job_id = '190'


My query reads the same textbox id three times


Here the view:



foreach($update_array as $val){

<table>
<tr>
<td><input class='txtedit' type='text' name='u_job_name[".$val['job_id']."]' value='".$val['job_name']."' /></td>

<td><input style='width: 50px;' class='savecheck' type='checkbox' name='savecheck[]' value=".$val['job_id']." /></td>

</tr>
</table>

}


What am i doing wrong?


Thank you guys.



asked 2 mins ago






Aucun commentaire:

Enregistrer un commentaire