Welcome Guest, Not a member yet? Register   Sign In
Status update via Select
#1

[eluser]sqwk[/eluser]
The following is part of a foreach loop that outputs rows from the database:

Code:
<select name="change_status">
    <option value="live_&lt;?=$row->id?&gt;"&lt;?if($row->status == 'live') echo " selected='selected'"; ?&gt;>Aktuell</option>
    <option value="standby_&lt;?=$row->id?&gt;"&lt;?if($row->status == 'standby') echo " selected='selected'"; ?&gt;>Standby</option>
    <option value="sold_&lt;?=$row->id?&gt;"&lt;?if($row->status == 'sold') echo " selected='selected'"; ?&gt;>Verkauft</option>
    <option value="failed_&lt;?=$row->id?&gt;"&lt;?if($row->status == 'failed') echo " selected='selected'"; ?&gt;>Erfolglos</option>
</select>

I would like the selects to update the status column for that particular entry. However, if all selects have the same name, then the last one will override the one that you are changing. If all selects have a different name, then I do not know what to check for in the controller. And if all selects are put into an array, I do not know how to isolate the one that has been changed by the user…

What is the best way to solve this without having tick-boxes and a change status select at the bottom of all entries?
#2

[eluser]theprodigy[/eluser]
Quote:<select name="change_status">
<option value="live_&lt;?=$row->id?&gt;"&lt;?if($row->status == 'live') echo " selected='selected'"; ?&gt;>Aktuell</option>
<option value="standby_&lt;?=$row->id?&gt;"&lt;?if($row->status == 'standby') echo " selected='selected'"; ?&gt;>Standby</option>
<option value="sold_&lt;?=$row->id?&gt;"&lt;?if($row->status == 'sold') echo " selected='selected'"; ?&gt;>Verkauft</option>
<option value="failed_&lt;?=$row->id?&gt;"&lt;?if($row->status == 'failed') echo " selected='selected'"; ?&gt;>Erfolglos</option>
</select>

Select boxes get sent in the post array via their name attribute. If you have 5 entries, it looks like every single one of your selects will have the same name. You may need to do the same thing to your select name as you are for the options

Code:
<select name="change_status_&lt;?=$row->id?&gt;">

That way, each select has it's own name, instead of all of them having the same name. Also, with doing this, you don't need to change the values of the options.

Try
Code:
<select name="change_status_&lt;?=$row->id?&gt;">
    <option value="live"&lt;?if($row->status == 'live') echo " selected='selected'"; ?&gt;>Aktuell</option>
    <option value="standby"&lt;?if($row->status == 'standby') echo " selected='selected'"; ?&gt;>Standby</option>
    <option value="sold"&lt;?if($row->status == 'sold') echo " selected='selected'"; ?&gt;>Verkauft</option>
    <option value="failed"&lt;?if($row->status == 'failed') echo " selected='selected'"; ?&gt;>Erfolglos</option>
</select>

So, change_status_1 could have live as it's value, change_status_2 could have sold, etc
#3

[eluser]sqwk[/eluser]
Thanks theprodigy. In that case how would I check in the controller which one has been submitted. There is no submit button as it is removed with javascript and the select submits on change. Normally I would check like so

Code:
$this->input->post('change_status')

but that is not possible anymore as I don't know what the name of the select would be. I could submit all selects as an array, but in that case I would need to update all entries on the page in the db, which I don't want to do as I also want to update the timestamp for the entry.
#4

[eluser]theprodigy[/eluser]
can you show me the full form being submitted? (including the foreach loop)
#5

[eluser]sqwk[/eluser]
Actually I just figured out a solution myself; Thanks for your help though…

In the viewfile:
Code:
<select name="change_status[]">
    <option&lt;?if($row->status == 'live') echo ' value="" selected="selected"'; else echo ' value="live_'.$row->id.'"';?&gt;>Aktuell</option>
    <option&lt;?if($row->status == 'standby') echo ' value="" selected="selected"'; else echo ' value="standby_'.$row->id.'"';?&gt;>Standby</option>
    <option&lt;?if($row->status == 'sold') echo ' value="" selected="selected"'; else echo ' value="sold_'.$row->id.'"';?&gt;>Verkauft</option>
    <option&lt;?if($row->status == 'failed') echo ' value="" selected="selected"'; else echo ' value="failed_'.$row->id.'"';?&gt;>Erfolglos</option>
</select>

and in the controller:
Code:
$array_statuses = $this->input->post('change_status');
foreach($array_statuses as $status) {
    if(!empty($status)) {
        $status_array = explode('_',$status);
        $status = $status_array['0'];
        $enquiry_id = $status_array['1'];
        break;
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB