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.

The helper thing is a great idea, liked that.

tinyint and varchar are about storage and performance. Tiny int is 1 byte, whereas varchar can be longer, related to your text: "pending" is 7 bytes for example. But using 0 (as number) is just 1.
And numeric comparison and filtering will be faster in your sql when compared with text comparison.

Thanks a lot for your feedback and help Smile

(05-15-2024, 03:22 AM)kcs Wrote: Thanks a lot for your feedback and help Smile

You're very welcome

Theme © iAndrew 2016 - Forum software by © MyBB