OK stuck again.... mySQL database search....
Posted: Thu Nov 10, 2011 9:54 am
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....
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....