Connecting Tech Pros Worldwide Forums | Help | Site Map

Select query problem

Jan Nordgreen
Guest
 
Posts: n/a
#1: Jul 17 '05
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(fdetails,'$fsearchstring')===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(fdetails,'$fsearchstring')===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
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Select query problem


"Jan Nordgreen" <room23111@hotmail.com> wrote in message
news:3488b88c.0403151712.5126495b@posting.google.c om...[color=blue]
> However, when I add the condition
> !(strpos(fdetails,'$fsearchstring')===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(fdetails,'$fsearchstring')===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 '%$fsearchstring%' // <-- 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_object 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.com - http://www.compguy.com/


Jan Nordgreen
Guest
 
Posts: n/a
#3: Jul 17 '05

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. :)
Closed Thread