I have 2 tables
test_pattern with column:
test_map with column
I have a website that retrieve a list of urls from test_map, and user are able to choose a url to insert into test_pattern
I'd came our with a working sql statement:
SELECT * FROM (SELECT NULL as id, url as url, "Ronny" as creator
from test_map where url LIKE '%www.abc/?%') as tmp WHERE NOT EXISTS (SELECT pattern FROM test_pattern WHERE pattern LIKE '%www.abc/?%');
However i don't know how to implement it in php, this is what i tried:
$sql = array(
sprintf('INSERT INTO %s SELECT * FROM (SELECT NULL as id, url as url, %s as creator FROM test_map WHERE url LIKE '%%s%')
AS tmp', "'".$creator."'", "'".$url."?'".
' WHERE NOT EXISTS (SELECT * FROM test_pattern WHERE url LIKE '%'.sprintf('%s',"'".$url."?'").'%') LIMIT 1'
);
Please assist on php implementation of the sql statement. Thanks
Set URL field in test_pattern as unique and then just do
WHERE url LIKE '$url%'
No need to test for the value if exists in test_pattern
I have found the issue, we can't use %s
directly in LIKE
like this %%s%.
To past value in between %%
, we need to do this %%%s%%