Get year (less than) from string (Varchar)

68 views Asked by At

It's my first post on StackOverflow. I have a small problem with sql query. I need search by year in topic title (phpbb3).

Now that is my code (result by year - ex. 2019):

// $search_by_year = 2019;
$sql_array = array(
    'SELECT'    => 'COUNT(t.topic_id) AS num_topics',
    'FROM'      => array(
        TOPICS_TABLE    => 't',
    ),
    'WHERE'     => '(t.topic_title LIKE "%'. $db->sql_escape($search_by_year). '%") AND t.forum_id = ' . $forum_id . ' AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.'),
);

I want to create second query to get topic less than X year. It is possible?

Something like this

(t.topic_title LIKE "%'. $db->sql_escape($search_by_year). '%") AND t.topic_title <= '2019'

But topic_title is Varchar (example - Best Computers for 2019) - not INT. Anyone can help?

0

There are 0 answers