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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grabber_grabbs
Forum Commoner
Posts: 60
Joined: Mon Oct 10, 2011 6:13 pm

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

Post 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....
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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";
grabber_grabbs
Forum Commoner
Posts: 60
Joined: Mon Oct 10, 2011 6:13 pm

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

Post 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.
Post Reply