php - How to search a column for an exact string in SQL -


my goal search column string b , if found, return row found in, , if wasn't found, need know in order take different course of action.

my current php code:

$string = "teststring"; $searchquery = "select *                   allstringstable                   `column_a` '$string'"  $searchresult = mysql_query($searchquery) or die(mysql_error()); $row = mysql_fetch_row($searchresult); echo "the returned row was: $row"; 

this breaks , nothing, think i'm way off here. also, have read exact string searching doesn't require wildcard substrings, etc, not needed. i'm not sure use instead...

you're there. need % wildcards:

// first, prevent sql injection mysql_real_escape_string $string = mysql_real_escape_string($string);  $searchquery = "select * allstringstable `column_a` '%{$string}%'"; //  ----------------------------------------------------------------^^^-------^^^  $searchresult = mysql_query($searchquery) or die(mysql_error());  if (mysql_num_rows($searchresult) == 0) {   echo "no rows found"; } else {    // need loop on result resource rows.   // better use mysql_fetch_array()   while ($row = mysql_fetch_array($searchresult)) {     $print_r $row; } 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -