Page 2 of 2
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Tue Nov 08, 2011 1:16 pm
by mikosiko
I did use the word "Ford" only following your example... the query is going to find any record where the "keyword" field value is present in your $row->title string
regarding your error... echo your query again to see if it is correct or not... and also I suggest you to change the usage of $row here
Code: Select all
while ($row = mysql_fetch_object($result))
to eliminate the conflict with your Object $row
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Tue Nov 08, 2011 1:23 pm
by simonmlewis
Ok.
The $row is for show here only, as it is named something else - but in essence, it should work as I have written it.
SELECT * FROM relate WHERE INSTR(Ford F150, keyword) > 0
This is what it echos.
Error remains.
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Tue Nov 08, 2011 1:35 pm
by mikosiko
SELECT * FROM relate WHERE INSTR(Ford F150, keyword) > 0
and what did you do to fix that?... the error is very evident... debug your code
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Tue Nov 08, 2011 1:39 pm
by simonmlewis
Sorry what?
$title or $row->title, is 'Ford F150'.
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Tue Nov 08, 2011 2:16 pm
by mikosiko
simonmlewis wrote: is 'Ford F150'.
yes... and
'Ford F150' is NOT the same than Ford F150 ...
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Tue Nov 08, 2011 2:19 pm
by simonmlewis
Heavens sorry, I meant it without the apostophies. Yes, I know that's vital.
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Wed Nov 09, 2011 9:36 am
by simonmlewis
Could you do something like this:
select everything from the relate db.
Echo the keyword.
Is $keyword similar to $title - if YES, show something.
And do this for all keywords.
So rather than querying the keywords in the SQL statement itself, extract all keywords, and then only show if they match.
But how would you do that in PHP - finding if a word is in a statement? ie. is keyword 'ford' in statement 'ford 150 truck'?
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Wed Nov 09, 2011 11:24 am
by mikosiko
it is possible, but no efficient....
why select all the records and then post-process them to chose the matching one?.... I don't see reason to do something like that....
what is wrong with the provided solution (it will select just the matching records)? did you tested/fixed the missing single quotes?
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Wed Nov 09, 2011 11:27 am
by simonmlewis
Yes and posted the error results back. All it did was to produce ALL records from the db.
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Wed Nov 09, 2011 11:36 am
by simonmlewis
relate WHERE INSTR(ford 150, keyword) > 0
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\xampp\phpMyAdmin\site\includes\product.inc on line 438
Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\xampp\phpMyAdmin\site\includes\product.inc on line 441
This is the error I get, after echoing the query.
The $row etc are all set correctly.
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Wed Nov 09, 2011 1:11 pm
by mikosiko
simonmlewis wrote:relate WHERE INSTR(ford 150, keyword) > 0
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\xampp\phpMyAdmin\site\includes\product.inc on line 438
Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\xampp\phpMyAdmin\site\includes\product.inc on line 441
This is the error I get, after echoing the query.
The $row etc are all set correctly.
and I did answer and show you which was the error.... let point it out again
WHERE INSTR(
ford 150, keyword) > 0
you don't see that ford 150 there doesn't have single quotes surrounding it? ... for that reason your query is INVALID... hence the errors that you get after that. what you must do is to be sure that the STRING that you are using is enclosed in single quotes... simple as that
Re: Basic query not working: where A is LIKE '%B%'...
Posted: Wed Nov 09, 2011 1:23 pm
by simonmlewis
Ok, well your initial code did not have quotes around it either.
However, I have put them in and BINGO! I've tried it on various products where there are keywords and arnt - and works perfect.
So thank you for your hard work in helping me.