atom_p Posted December 3, 2010 Share Posted December 3, 2010 This is the first time Im trying to use REGEXP, but cant get it working. It gives no error, just nothing..Anyone got idea why, please? Thanks <?php include ('connectToDatabase.php'); $getSearch = $_REQUEST['getSearch']; $keywordSearchQuery = "SELECT shoeName, shoeSize, colour, price, gender, description WHERE shoeName REGEXP '.*($getSearch).*' || shoeSize REGEXP '.*($getSearch).*' || colour REGEXP '.*($getSearch).*' || price REGEXP '.*($getSearch).*' || gender REGEXP '.*($getSearch).*' || description REGEXP '.*($getSearch).*" ; $keywordSearchQueryResult = mysql_query($keywordSearchQuery); echo "$keywordSearchQueryResult"; ?> Link to comment https://forums.phpfreaks.com/topic/220548-regexp-not-working-properly/ Share on other sites More sharing options...
robert_gsfame Posted December 3, 2010 Share Posted December 3, 2010 Case like yours, you probably should use LIKE so instead of shoeName REGEXP '.*($getSearch).*' u can use shoeName LIKE '%$getsearch%' but if you still wish to use REGEXP, you can try this shoeName REGEXP '[[:<:]]".$getsearch."[[:>:]]'=1 100% must work! hope that helps Link to comment https://forums.phpfreaks.com/topic/220548-regexp-not-working-properly/#findComment-1142550 Share on other sites More sharing options...
Pikachu2000 Posted December 3, 2010 Share Posted December 3, 2010 There's a strong possibility that the query is failing to execute, but you don't check for that condition. Even if the query succeeds, the $keywordSearchQueryResult variable wouldn't hold a value, it would hold a query result resource. You need to access the result resuorce with the appropriate function, such as mysql_result or one of the mysql_fetch_*() functions. if( $keywordSearchQueryResult = mysql_query($keywordSearchQuery) ) { if( mysql_num_rows($keywordSearchQueryResult) > 0 ) { while( $array = mysql_fetch_assoc($keywordSearchQueryResult) ) { echo '<pre>'; print_r($array); echo '</pre>'; // just prints out the contents of each record. Nothing fancy. } } else { echo 'Query succeeded, but returned 0 results.'; } } else { echo "<br>Query string: $keywordSearchQuery<br>Produced error: " . mysql_error() . '<br>'; } P.S. It would also be helpful to know what you're trying to accomplish . . . Link to comment https://forums.phpfreaks.com/topic/220548-regexp-not-working-properly/#findComment-1142687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.