MyBB Community Forums
Match string in SQL? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: Match string in SQL? (/thread-172120.html)



Match string in SQL? - marcus123 - 2015-06-19

$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?


RE: Match string in SQL? - martec - 2015-06-19

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.


RE: Match string in SQL? - marcus123 - 2015-06-19

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.


RE: Match string in SQL? - Destroy666 - 2015-06-21

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';



RE: Match string in SQL? - marcus123 - 2015-06-22

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?