MyBB Community Forums

Full Version: Match string in SQL?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
$query2 = $db->query("
        SELECT c.url, c.id
        FROM ".TABLE_PREFIX."content c
		WHERE c.url LIKE '%".$db->escape_string_like($mybb->input['id'])."%'
		limit 1
    ");
	
	
			$test = $db->fetch_array($query2);
			
			echo $test['id'];

I am trying to match this in SQL this-is-a-test then return ID of the column that matches it 100%. The problem is when it doesn't match any it juts returns 1

That mean it always shows thread content with the ID 1 for errors!

How to show an error or some when the search is negative?
You create several thread in this folder (Plugin Development), but does not publish any plugin.
If it is just to ask questions about PHP, there are communities especially for this. Here should not be the place.
This forum is called plugin development not plugin sharing Smile And yes I can ask this question on some other PHP forum but since this plugin is MYBB based many will have no idea about how to make this work fine with MYBB specially when it uses it's own functions.
I don't see how it returns 1.. Unless thread with ID 1 has a URL that always matches your query - note that it may be LIKE '%%' if the input is empty, but then I don't know how you handle that case because once again you posted only parts of your code... You'd need to add this in that case:
AND c.url != ''

Also, this is slightly more proper:
echo !empty($test['id']) ? $test['id'] : 'nothin';
When I was using LIKE it was matching similar strings!

This one seems to work!

$search = "this-is-a-test-title";

$query = $db->query("
        SELECT a.id, a.url
        FROM ".TABLE_PREFIX."ads a
	WHERE a.url IN ('".$search."')
    ");
	
	
			while($row = $db->fetch_array($query))
			{
				
		echo $row['id'];

			}


Looks like it checks if it's 100% not like similar. Am I right?