MyBB Community Forums

Full Version: Query Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I need some help with a MyBB query.

I have a search form which finds all rows which are related to what is searched. For example, if I search "blue", it will return all rows with the word "blue" in it.

Here's what I'm using:

$query = $db->query("SELECT * FROM ".TABLE_PREFIX."_tablename WHERE column LIKE %".$search_query."% ORDER BY id");

But it's not working.

What's the proper way to do this?

Thanks.
use the built-in query functionality, plus your quotes are wrong as is your use of the table prefix.

$query = $db->simple_select("tablebasename", "*", "column LIKE '%{$search_query}%', array('order_by' => 'id'));

tablebasename is "users" or "threads" and typically does not include the leading "_"
the table_prefix includes the trailing "_" in most cases
the single quotes go outside the %'s
you can put the order by clause in the options array

using this method is cross-db compatible and setup to use the proper write_query method