Welcome Guest, Not a member yet? Register   Sign In
how to use set_select on a form to show the old value?

Thank you for your help and suggestions.

Quote:demyr So, Why don't you just use :<option value="pending" <?php if($booking->status == "pending"){echo 'selected';} ?>>Pending</option>

That's what I did in the end. Created a little helper: 

PHP Code:
function isSelected($selectName$value) {
    if(isset($value)) {
        if($selectName == $value) return 'selected';
    return false;

And I can use it on all my selects. I just don't like to do ifs and echos inside the html, i find the readability messy.  Angel

PHP Code:
<option value="confirmed" <?= isSelected('confirmed'$booking->status) ;?>>Confirmed</option> 

I thought the set_select function would do that for me, but I understood it wrong.

Quote:By the way, keep your status as tiny_int in your database instead of varchar.
0 = pending
1 = option
2 = confirmed
I am using varchar for the status because I find them also more readable, but I am always happy to improve my code and learn. Can you explain your recommendation? Is it for performance? to prevent the database to become too heavy? I won't have more than maybe a hundred of records per year in the bookings table.    

Quote:Additionally, in your method be careful with double semicolon
->first();; and try to place "where" after "join"s.
Thanks for spotting that, I corrected it.

Messages In This Thread
RE: how to use set_select on a form to show the old value? - by kcs - 05-14-2024, 01:40 PM

Theme © iAndrew 2016 - Forum software by © MyBB