php - MySQL select only using first word of variable -



php - MySQL select only using first word of variable -

i using php , mysql. have select query not working. code is:

$bookquery = "select * my_books book_title = '$book' or book_title_short = '$book' or book_title_long = '$book' or book_id = '$book'";

the code searches several title types , returns desired reference of time, except when name of book starts numeral. though rare, of book titles in form "2 book". in such cases, query looks @ "2", assumes "book_id" , returns sec entry in database, instead of entry "2 book". "3 book" returns 3rd entry , forth. confused why select acting way, more importantly, not know how prepare it.

if have column in table numeric info type (int, maybe), search strategy going work strangely values of $book start numbers. have discovered this.

the next look returns true in sql. it's not intuitive, it's true.

99 = '99 luftballon'

that's because, when compare integer string, mysql implicitly this:

cast(stringvalue int)

and, cast of string origin text of integer returns value of integer. example, value of

cast('99 luftballon' int)

is 99. you'll book id 99 if search term.

it's pointless seek compare int column text string doesn't start integer, because cast('blah blah blah' int) returns zero. create search strategy work better, should consider omitting or book_id = '$book' search query unless know entirety of $book number.

php mysql

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -