PHP MySQL string LIKE
Posted: Mon Jul 26, 2010 6:32 am
Hi.
I have this little problem. I take data from MySQL using search field.
I have this code to compare if any field "number" has the same value and try to echo it on the screen.
Problem is: It understand what it supposed to too. Like: When i search a code (find data from field "kood") it understands that i have to look for the "number" field, compare if any other MySQL line has the same value and print them both not only the line that has the "Code" i serached. That's because i want to know if that person has ordered anything else or only this certain piece. Well it works for me but only if i have exactly the same value in the "number" field.
When i have a code lets say:
1234 and the orderers name is John Smith 987654
2345 and the orderers name is Smith John 987654
Now i search the product code 1234 i get the result: (search engine uses the string and looks fields: kood, nimetus,number)
1234 and the name is John Smith.
Well i know that he has some more products. Now when i serch the Smith (again search engine uses the string and looks fields: kood, nimetus,number) i get the result:
1234 and the orderers name is John Smith 987654
2345 and the orderers name is Smith John 987654
bacuse string Smith is in number filed and the other line has the Smith string in it it displays both lines.
But when i search: John Smith 987654
it wont show me the line: Smith John 987654
How can i do that: John Smith 987654 = Smith John 987654
That's the main question.
I have this little problem. I take data from MySQL using search field.
I have this code to compare if any field "number" has the same value and try to echo it on the screen.
Code: Select all
$query = mysql_query("SELECT id, date, kood, kogus, nimetus, number, kes, komm, staatus, ladu FROM tellimus WHERE kood like '%$otsi%' or nimetus like '%$otsi%' or number like '%$otsi%' or komm like '%$otsi%' order by id");
//display row
while ($row = mysql_fetch_array($query)) {
$numberotsi=$row['number'];
}
$_SESSION['vali'] = "WHERE kood like '%$otsi%' or nimetus like '%$otsi%' or komm like '%$otsi%' or number like '%$otsi%' or number like '%$numberotsi%' order by id" or die ('Error: ' . mysql_error());
When i have a code lets say:
1234 and the orderers name is John Smith 987654
2345 and the orderers name is Smith John 987654
Now i search the product code 1234 i get the result: (search engine uses the string and looks fields: kood, nimetus,number)
1234 and the name is John Smith.
Well i know that he has some more products. Now when i serch the Smith (again search engine uses the string and looks fields: kood, nimetus,number) i get the result:
1234 and the orderers name is John Smith 987654
2345 and the orderers name is Smith John 987654
bacuse string Smith is in number filed and the other line has the Smith string in it it displays both lines.
But when i search: John Smith 987654
it wont show me the line: Smith John 987654
How can i do that: John Smith 987654 = Smith John 987654
That's the main question.