Re: Select query problem

From: Steven C. Gallafent (steve_at_compguy.com)
Date: 03/16/04


Date: Mon, 15 Mar 2004 21:35:13 -0700


"Jan Nordgreen" <room23111@hotmail.com> wrote in message
news:3488b88c.0403151712.5126495b@posting.google.com...
> However, when I add the condition
> !(strpos(fdetails,'$fsearchstring')===false),
> $result is false.

You're feeding PHP code to the MySQL interpreter and it has absolutely no
clue what you're talking about.

> $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(fdetails,'$fsearchstring')===false)
> ORDER BY fdate, fpostdate
> ");

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 '%$fsearchstring%' // <-- LOOK HERE
  ORDER BY fdate, fpostdate

> Even simpler stuff like:
> 'and strpos('abc','c')>0'

More PHP code that MySQL doesn't understand.

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

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.

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

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_object or one of a half-dozen other commands.

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

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.com - http://www.compguy.com/


Relevant Pages

  • Re: from mysql to php
    ... Carl Pearson wrote: ... It wouldn't actually *be* PHP code, but MySQL code that generates the structure. ... PHP would just be calling its various MySQL functions to accomplish the task. ...
    (alt.php)
  • Re: Counting query problem
    ... created a developer server on my local machine and when I run the PHP code against the MySQL table that I imported from my ISP's website everything works fine. ... All this code worked prior to my ISP upgrading their MySQL and phpMyAdmin software. ...
    (comp.lang.php)
  • Re: Ajax.Request
    ... I am using prototype.js to save data into MySQL using Ajax.Request ... otherwise I am just updating it. ... Your problem seems more likely to be on the client side, ... so looking at the PHP code is ...
    (comp.lang.php)
  • Re: PhP call on conditions
    ... twins wrote: ... When a file is created in a directory in local computer. ... When the mysql date stored in the DB approaches the current date and time. ... Its not good to have the php code running in the background and waiting ...
    (comp.lang.php)
  • Re: [PHP] Date
    ... There's another way out there using mysql ... as fDate ... Richard Heyes ... Knowledge Base and HelpDesk software ...
    (php.general)