I have in my database a table called semester that has only the ID field and the SEMESTER NAME field. If I query the current semester I get "1 semester - 2021", what I need is to extract only the year from that query.
TABLE SEMESTER ID (INT 11) NAME_SEMESTER (VARCHAR 50)
SELECT * FROM semestres
WHERE id= $form_id_1;
RESULT = 1 SEMESTER - 2021
You can use the substring_index function , getting the last element and with the - separator, you can apply the trim function to remove trailing and leading whitespace.