I hope I understood your question correctly. From what I see you have packets and you need to be able to change their statuses.
What I did:
- I used your example, but kept only the necessary info: current status, possible statuses to be modified
- I eliminated the change link on each line and moved it once, at the end
- I introduced a notion of packet ID, which is bassicaly the key of the array $paketi_list
The code below is pretty self explanatory, but to sumarize:
- I assume you have 3 statuses
- I use jQuery to switch the status, whenever a person clicks on a button + I update a hidden field in a form so that the changed can be saved later
- the form processing is done on the same page
- I tested this using a dummy array with WAMP and it works just fine
If you want to test , just copy the next 3 sections in the same file - I had to split them in 3 because the site would not let me paste everything in one code region.
You can see how it works here: http://screencast-o-matic.com/watch/c2hqVcnazP
By the way, I think you got voted down because you didn't provide evidence that you tried something on your end, so next time try something and if it is not working, provide the code you tried out and you'll get comments on that.
PHP - variable initialization + form treatment
<?php
//modify next line with all your statuses
$arrayAllStatuses = array ('Status 1', 'Status 2', 'Status 3');
/* used for example purposes - to replace with your own code */
$paketi_list = array (
array('seisundi_liik' => 'Status 2'),
array('seisundi_liik' => 'Status 3'),
array('seisundi_liik' => 'Status 1')
);
/* ========== */
//this next part is the code responsible for treating the form submission
//you can move this elsewhere (as long as you update the action attribute of the form tag)
if (isset($_POST['change_status'])) {
$numberOfLines = $_POST['numberOfLines'];
foreach ($paketi_list as $currentId => $pakett) {
if (isset($_POST['current_status_row_' . $currentId]) && $_POST['current_status_row_' . $currentId] != '') {
echo 'Packet with ID = ' . $currentId . ' has a new status = ' . $_POST['current_status_row_' . $currentId];
//I imagine you want to save this to a database - sanitize it first using mysqli_real_escape_string
echo "<br />";
}
}
}
?>
HTML part - the table and the form containing the modified statuses
<table border="1">
<tr>
<th>Status</th>
<th>Change status to</th>
</tr>
<?php foreach ($paketi_list as $currentId => $pakett): ?>
<tr>
<td id="status_row_<?php echo $currentId; ?>"><?php echo $pakett['seisundi_liik']; ?></td>
<?php
$remainingUnusedStatuses = array_diff($arrayAllStatuses, array($pakett['seisundi_liik']));
//next line rebases array keys - so you don't end up with an array that has a key of 0 & 2 or 1 & 2
$remainingUnusedStatuses = array_values($remainingUnusedStatuses);
?>
<td>
<button id="tochange-first_row_<?php echo $currentId; ?>"><?php echo $remainingUnusedStatuses[0]; ?></button>
<button id="tochange-second_row_<?php echo $currentId; ?>"><?php echo $remainingUnusedStatuses[1]; ?></button>
</td>
</tr>
<?php endforeach; ?>
</table>
<form action="" method="post">
<input type="hidden" name="numberOfLines" value="<?php echo sizeof($paketi_list); ?>">
<?php foreach ($paketi_list as $currentId => $pakett): ?>
<input type="hidden" id="current_status_row_<?php echo $currentId; ?>" name="current_status_row_<?php echo $currentId; ?>" value="">
<?php endforeach; ?>
<input type="submit" value="Save changes" name="change_status">
</form>
The JS - you need jQuery and some functions
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(function() {
$("button[id^='tochange']").click(function() {
var currentRow = getCurrentRow($(this));
var currentButtonId = $(this).attr('id');
//get current status
var currentStatus = $("td#status_row_" + currentRow).html();
var futureStatus = $("button#" + currentButtonId).html();
//switch the two statuses (visually)
$("button#" + currentButtonId).html(currentStatus);
$("td#status_row_" + currentRow).html(futureStatus);
//save the change in the hidden form field
$("input#current_status_row_" + currentRow).val(futureStatus);
//$("#btnAddProfile").html('Save');
});
});
function getCurrentRow(currentObject)
{
//do not use any numerical values in the id, except at the end, otherwise this won't work anymore
var currentRow = ($(currentObject).attr('id').match(/\d+/));
return currentRow;
}
</script>
Hope this helps - it kept me busy for a while, but I needed a change from my current project.