Page 1 of 1

OK stuck again.... mySQL database search....

Posted: Thu Nov 10, 2011 9:54 am
by grabber_grabbs
Here is my problem. i want to make a query in my mySQL database using multiple WHERE....
if i use one WHERE only, it works fine, its shows all the items in the selected department. But if i want all the item
that has a specific word in it ($varsearch in my example) i have an error saying
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

in my example, descshort is a field in my $dbtable and the field exist.

Spent all the morning trying to find where the mistake is.... arghh.... its probably simple but i am just starting with PHP and MySQL.... hope you guys can help me on this. Thanks again.

if (!empty($varsearch)) {

$SQL = "SELECT * FROM $dbtable WHERE dept LIKE '%". $pagedept ."%' AND (stristr(descshort , $varsearch) !== false ) LIMIT $page, $limit";
}
else {
// here i have no error and the system display all the items within a certain department.
$SQL = "SELECT * FROM $dbtable WHERE dept LIKE '%". $pagedept ."%' LIMIT $page, $limit";
}
$result = mysql_query($SQL);
while ($db_field = mysql_fetch_assoc($result))
{ blah blah....

Re: OK stuck again.... mySQL database search....

Posted: Thu Nov 10, 2011 10:02 am
by Celauran
stristr() is a PHP function, not an SQL function. Does this not work?

Code: Select all

$SQL = "SELECT * FROM $dbtable WHERE dept LIKE '%". $pagedept ."%' AND descshort LIKE '%{$varsearch}%' LIMIT $page, $limit";

Re: OK stuck again.... mySQL database search....

Posted: Thu Nov 10, 2011 12:03 pm
by grabber_grabbs
arghhh.. you are right.... should have known here....
thanks again Celauran for helping here.

was working also with this syntax : '%". $pagedept ."%' but i probably did a mistake while typing it, because it was not working when i tested it...

Celauran, you are a big asset to this forum. I cannot say thank you ennough, for all the help you provide here.