I have a custom table in my Wordpress database and have a custom query that runs against it and displays the data in a custom template.
This is the query
$query =" SELECT * FROM cp WHERE year = $cp_year AND quarter = $cp_quarter AND volume = $cp_volume AND page <= $cp_page ORDER BY page DESC LIMIT 1 ";
This works fine as long as $cp_volume is an integer but if it is a string variable such as 1a the query fails with this error message
WordPress database error: [Unknown column '2a' in 'where clause'] SELECT * FROM cp WHERE year = 1911 AND quarter = 4 AND volume = 2a AND page <= 1475 ORDER BY page DESC LIMIT 1
volume is declared as varchar in the database table.
I have been struggling and searching on Google for several hours without success. Anyone got any bright ideas please?