Variable in boolean query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rhio Barnhart

    Variable in boolean query

    I am a MySQL/PHP beginner and have gotten further than I expected. I am
    developing a web based library catalog. After getting everything
    configured, I have been working on various query formats. System is Mac
    OS 10.3.8, PHP 5, MySQL 4.1.

    I would like to use boolean queries as shown below, but I cqn't seem to
    get the $_POST variable sytax correct. Any pointers would be enormously
    helpful.

    From the MySQL command line, this query works:

    mysql> select * from record where match
    (author,title,n otes,other_entr ies) against ('+beethoven +symphonies' in
    boolean mode);


    However, when trying to take form input and build the same query in a
    PHP script, something in the following doesn't work:


    $name = $_POST['name'];
    $title = $_POST['title'];


    $result = mysql_query ("select * from record where match
    (author,title,n otes,other_entr ies) against ('+$name +$title' in boolean
    mode)"), $connection);



    For comparison purposes, the following works perfectly on my system:

    $result = mysql_query ("select * from record where author regexp
    '$name' and title regexp '$title'", $connection);


    Thanks,
    RHB
  • Jan Pieter Kunst

    #2
    Re: Variable in boolean query

    Rhio Barnhart wrote:
    [color=blue]
    > $result = mysql_query ("select * from record where match
    > (author,title,n otes,other_entr ies) against ('+$name +$title' in boolean
    > mode)"), $connection);[/color]

    Untested, but try this:

    $result = mysql_query ("select * from record where match
    (author,title,n otes,other_entr ies) against ('+{$name} +{$title}' in
    boolean mode)"), $connection);

    or this:


    $result = mysql_query ("select * from record where match
    (author,title,n otes,other_entr ies) against ('+" . $name . ' +' . $title
    .. "' in boolean mode)"), $connection);


    I have the feeling that the '+' in '+$varname' is being interpreted as
    an arithmetic operator. I could be totally wrong, though.

    JP

    --
    Sorry, <devnull@cauce. org> is a spam trap.
    Real e-mail address unavailable. 5000+ spams per month.

    Comment

    Working...