Jump to content

REGEXP not working properly


atom_p

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.