![]() |
how to use set_select on a form to show the old value? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: how to use set_select on a form to show the old value? (/showthread.php?tid=90853) Pages:
1
2
|
RE: how to use set_select on a form to show the old value? - kcs - 05-14-2024 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) { ![]() 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.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 semicolonThanks for spotting that, I corrected it. RE: how to use set_select on a form to show the old value? - demyr - 05-15-2024 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. RE: how to use set_select on a form to show the old value? - kcs - 05-15-2024 Thanks a lot for your feedback and help ![]() RE: how to use set_select on a form to show the old value? - demyr - 05-15-2024 (05-15-2024, 03:22 AM)kcs Wrote: Thanks a lot for your feedback and help You're very welcome |