473,471 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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(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
Jul 17 '05 #1
2 2027
"Jan Nordgreen" <ro*******@hotmail.com> wrote in message
news:34**************************@posting.google.c om...
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.
st***@compguy.com - http://www.compguy.com/
Jul 17 '05 #2
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. :)
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
2
by: Pavel Stehule | last post by:
Hello, Pg make query 1. and 2. very fast (use index), but for query 3. dont use index. I can solve its using select union, but I readed so pg 7.5 don't problem with OR operator. I use cvs pg. I...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
by: VMB | last post by:
Using version: 4.0.18-Max-log We're getting some fairly poor performance when doing an INSERT INTO temp_table ... SELECT (...). The SELECT is grabbing 2K row chunks from its table, so the...
12
by: bokke | last post by:
Hi, I have a page with a link <a href="Contributor.php?action=&SubCat=<?php echo $row; ?>"><?php echo $row;?></a> that does to a page with a SELECT $query = "SELECT * FROM news WHERE...
4
by: Konrad Hammerer | last post by:
Hi! I have the following problem: I have a query (a) using another query (b) to get the amount of records of this other query (b), means: select count(MNR) as Number from...
1
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an...
4
by: The.Daryl.Lu | last post by:
Hi, Have a bit of a problem... I've created a form in Access and will use the form for a user to query a table based on the selected fields. The problem lies in that I was using checkboxes for...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.