Select query problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jan Nordgreen

    Select query problem

    I use php4 and winxp.

    This query works as expected:

    $result = mysql_query("
    SELECT feventid, UNIX_TIMESTAMP( fdate) as fdate, ftitle, fpostedby,
    fdetails, factive, UNIX_TIMESTAMP( fpostdate) as fpostdate
    FROM events
    WHERE
    fdate between '$datefrom' and '$dateto'
    and factive
    and fpostdate <= curdate()
    ORDER BY fdate, fpostdate
    ");

    However, when I add the condition

    !(strpos(fdetai ls,'$fsearchstr ing')===false),

    $result is false.

    $result = mysql_query("
    SELECT feventid, UNIX_TIMESTAMP( fdate) as fdate, ftitle, fpostedby,
    fdetails, factive, UNIX_TIMESTAMP( fpostdate) as fpostdate
    FROM events
    WHERE
    fdate between '$datefrom' and '$dateto'
    and factive
    and fpostdate <= curdate()
    and !(strpos(fdetai ls,'$fsearchstr ing')===false)
    ORDER BY fdate, fpostdate
    ");

    Even simpler stuff like:

    'and strpos('abc','c ')>0'

    does not work.

    I made two more discoveries trying to crack the problem.

    '0=0', is an acceptable condition, while 'true' is not.

    For the first query, $result does not return true, but 'Resource id #3'.

    I have just started with php. What am I doing wrong?

    Regards,

    Jan Nordgreen
  • Steven C. Gallafent

    #2
    Re: Select query problem

    "Jan Nordgreen" <room23111@hotm ail.com> wrote in message
    news:3488b88c.0 403151712.51264 95b@posting.goo gle.com...[color=blue]
    > However, when I add the condition
    > !(strpos(fdetai ls,'$fsearchstr ing')===false),
    > $result is false.[/color]

    You're feeding PHP code to the MySQL interpreter and it has absolutely no
    clue what you're talking about.
    [color=blue]
    > $result = mysql_query("
    > SELECT feventid, UNIX_TIMESTAMP( fdate) as fdate, ftitle, fpostedby,
    > fdetails, factive, UNIX_TIMESTAMP( fpostdate) as fpostdate
    > FROM events
    > WHERE
    > fdate between '$datefrom' and '$dateto'
    > and factive
    > and fpostdate <= curdate()
    > and !(strpos(fdetai ls,'$fsearchstr ing')===false)
    > ORDER BY fdate, fpostdate
    > ");[/color]

    SELECT feventid, UNIX_TIMESTAMP( fdate) as fdate, ftitle, fpostedby,
    fedetails, factive, UNIX_TIMESTAMP( fpostdate) as fpostdate
    FROM event
    WHERE fdate between '$dateform' and $dateto'
    AND factive
    AND fpostdate <= curdate()
    AND fdetails LIKE '%$fsearchstrin g%' // <-- LOOK HERE
    ORDER BY fdate, fpostdate
    [color=blue]
    > Even simpler stuff like:
    > 'and strpos('abc','c ')>0'[/color]

    More PHP code that MySQL doesn't understand.
    [color=blue]
    > '0=0', is an acceptable condition, while 'true' is not.[/color]

    0=0 evalutes to 1 (which we humans interpret as true).
    MySQL doesn't know what 'true' means. PHP does because it is defined as part
    of the language.
    [color=blue]
    > For the first query, $result does not return true, but 'Resource id #3'.[/color]

    For the first query (which is all valid MySQL), you get back a resource
    which you then use to retrieve the returned data using something like
    mysql_fetch_obj ect or one of a half-dozen other commands.
    [color=blue]
    > I have just started with php. What am I doing wrong?[/color]

    Feeding PHP to the MySQL interpreter.

    It would probably be worth your while to put your queries through a
    command-line MySQL session to make sure that they're valid. That way you
    know that your queries are good and any problems that remain are a problem
    with your PHP code.

    Steve
    --
    Steven C. Gallafent - The Computer Guy, Inc.
    steve@compguy.c om - http://www.compguy.com/


    Comment

    • Jan Nordgreen

      #3
      Re: Select query problem

      Steve,

      Thanks a lot! You have pushed me one big step forward in my php/mysql
      stumblings.

      Regards,

      Jan

      PS:

      Now I know why my Google searches for mysql queries with strpos() in
      them where fruitless. :)

      Comment

      Working...