473,657 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ 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(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
Jul 17 '05 #1
2 2038
"Jan Nordgreen" <ro*******@hotm ail.com> wrote in message
news:34******** *************** ***@posting.goo gle.com...
However, when I add the condition
!(strpos(fdetai ls,'$fsearchstr ing')===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(fdetai ls,'$fsearchstr ing')===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 '%$fsearchstrin g%' // <-- 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_obj ect 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.c om - 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
3540
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
6449
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 COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
1
4170
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 couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
2
1899
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 used vacuum analyze first. table sp_op_product has 15K rows, sp_op_uct 37K rows; regards Pavel Stehule
6
4839
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 SalesManName AT Alan Time
2
6467
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 problem is not that the query results are so monstrous that it's just taking that long to gather them all. The problem appears to be one of IO. When an INSERT...SELECT is run, the SELECT part of the query is run first and those results saved in a...
12
1667
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 writer='$SubCat' ";
4
4293
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 Jahrbuch_Einzelversand_Komplett (while Jahrbuch_Einzelversand_Komplett is a query itself)
1
3612
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 "interface" in Access. It's like a little system to make a production plan. It must get information about part numbers, description, set where the part number belongs, quantity of part numbers that the set uses, stock number(this is a text value, it...
4
10577
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 the fields and noticed that if I don't check a box, then the query will look specifically in the table for where the applicable field is FALSE. This isn't right however and decided that I should use a radio button group so that the user can select...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.