473,729 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Select" & "Order By" OK- ''WHERE'' Does'nt Work !

Before i post actual code, as i need a speedyish reply.
Can i first ask if anyone knows off the top of their head, if there is
a likely obvious cause to the following problem.
For the moment i've reduced my form request to a simple text string
entry, instead of my desired optional parameters. As i have been stuck
with a single unfathomable glitch for over a year.
Basically, if i enter queries such as ;
"select * from table" "select * from table order by artist",
it works perfectly. However if i introduce the 'where' option, as in
"select * from table where artist like whatever". It comes back with
"could not execute query". This happens even if i append "order by" to
it.
I'll post all the various codes if anyone can please help.
Jul 17 '05 #1
23 5679

On 31-Oct-2003, i.*******@onmai l.co.uk (ian justice) wrote:
Before i post actual code, as i need a speedyish reply.
Can i first ask if anyone knows off the top of their head, if there is
a likely obvious cause to the following problem.
For the moment i've reduced my form request to a simple text string
entry, instead of my desired optional parameters. As i have been stuck
with a single unfathomable glitch for over a year.
Basically, if i enter queries such as ;
"select * from table" "select * from table order by artist",
it works perfectly. However if i introduce the 'where' option, as in
"select * from table where artist like whatever". It comes back with
"could not execute query". This happens even if i append "order by" to
it.
I'll post all the various codes if anyone can please help.


I teach students how to program. Almost every student is convinced, at one
time or another, that they have found a bug in the compiler, operating
system or hardware. In every case it's a problem with the student's code.

You are suggesting that somehow the SQL select where order by is broken for
some unspecified database system. The odds are about the same as my winning
the lottery without buying a ticket.

assuming the table and columns are correctly defined and the connection is
open and the database is selected and I haven't made a typo, the following
will work
"select * from sometable where somecolumn like 'somevalue%' order by
somecolumn"

If you want to help yourself
1) echo the actual SQL statement
2) add error capture code (e.g. 'or die(mysql_error ())') to your connect,
dbselect and query calls

If you want more help here
1) show us the actual code including the echoed sql statement and error
message if any
2) show us the table definition
3) tell us which database you are using and what version
4) tell us the version of PHP and if it's in safe mode
--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@wil lglen.net (it's reserved for spammers)
Jul 17 '05 #2
i.*******@onmai l.co.uk (ian justice) schrieb:
Before i post actual code, as i need a speedyish reply.
Can i first ask if anyone knows off the top of their head, if there is
a likely obvious cause to the following problem.
For the moment i've reduced my form request to a simple text string
entry, instead of my desired optional parameters. As i have been stuck
with a single unfathomable glitch for over a year.
Basically, if i enter queries such as ;
"select * from table" "select * from table order by artist",
it works perfectly. However if i introduce the 'where' option, as in
"select * from table where artist like whatever". It comes back with
"could not execute query". This happens even if i append "order by" to
it.


Are you sure that youre query string looks like
select id from table order by id
and not like
select id from tableorder by id
?

Please give us the version of PHP, the name of the DBMS that you're
using and some small example code.

Regards,
Matthias
Jul 17 '05 #3
That was beautiful sir.
Jul 17 '05 #4
Matthias Esken <mu************ ******@usenetve rwaltung.org> wrote in message news:<bn******* ***@usenet.eske n.de>...

Are you sure that youre query string looks like
select id from table order by id
and not like
select id from tableorder by id
? Yes
I'm writing this via web tv, however come Sunday i should be able to access a PC
and i'll post all the scripts.
Please give us the version of PHP, the name of the DBMS that you're
using and some small example code.

Regards,
Matthias

I'm using;
PHP4u Version 3.0 Based on PHP-4.3.2
MySQL 3.23.52
Thanks for your time so far.
Jul 17 '05 #5
>
I'm using;
PHP4u Version 3.0 Based on PHP-4.3.2
MySQL 3.23.52
Thanks for your time so far.

Correction MySQL 3.23.56
Jul 17 '05 #6
"Tom Thackrey" <us***********@ nospam.com> wrote in message news:<rc******* **********@news svr14.news.prod igy.com>...

I teach students how to program. Almost every student is convinced, at one
time or another, that they have found a bug in the compiler, operating
system or hardware. In every case it's a problem with the student's code.
I'm presuming it is my fault
You are suggesting that somehow the SQL select where order by is broken for
some unspecified database system. The odds are about the same as my winning
the lottery without buying a ticket.


Honestly not remotely suggesting such a thing :)

I'm replying to this via webtv, so unfortunately the rest of your
message can't be quoted as it doesn't show up on the reply form.
However, hopefully on Sunday i will be able to access a PC again. I
will then post the scripts.

I had already tried the syntax you suggested without success. The
database and MySQL connection are fine, as they select, sort and
display the results of a query such as "select * from table order by
column".

The versions i am using are as follows;
PHP4u Version 3.0 Based on 4.3.2
MySQL 3.23.56
Many thanks for your time and help so far, it's very much appreciated.
Jul 17 '05 #7

On 31-Oct-2003, i.*******@onmai l.co.uk (ian justice) wrote:
I had already tried the syntax you suggested without success. The
database and MySQL connection are fine, as they select, sort and
display the results of a query such as "select * from table order by
column".

The versions i am using are as follows;
PHP4u Version 3.0 Based on 4.3.2
MySQL 3.23.56
Many thanks for your time and help so far, it's very much appreciated.


What error message did you get when you executed the query?
Are you sure there are records in the table that match your pattern?
If the syntax is correct, then the problem is probably with the table or
column names. Are you using reserved words for either of these? Do they
exist?

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@wil lglen.net (it's reserved for spammers)
Jul 17 '05 #8
"Tom Thackrey" <us***********@ nospam.com> wrote in message news:<FW******* ***********@new ssvr14.news.pro digy.com>...
What error message did you get when you executed the query?
Are you sure there are records in the table that match your pattern?
If the syntax is correct, then the problem is probably with the table or
column names. Are you using reserved words for either of these? Do they
exist?


The error message was "could not execute query". This is my own error
message as in
$rs=mysql_query ($sql, $conn) or die ("could not execute query");

The records do exist i deliberately used simple one-word requests as
well. I also
checked i got the same error message by typing in a load of random
letters in the
text field.
The table is called 'music' and the columns are headed 'song' 'folder'
format' 'artist'.

Whether it's relevant to solving the puzzle, i don't know. But, i
stress again that i am
successfully connected to mysql and the database. As, it does
correctly sort and display
the result by the chosen 'order by' command, be it song, folder,
format or artist.
Jul 17 '05 #9

On 1-Nov-2003, i.*******@onmai l.co.uk (ian justice) wrote:
"Tom Thackrey" <us***********@ nospam.com> wrote in message
news:<FW******* ***********@new ssvr14.news.pro digy.com>...
What error message did you get when you executed the query?
Are you sure there are records in the table that match your pattern?
If the syntax is correct, then the problem is probably with the table or
column names. Are you using reserved words for either of these? Do they
exist?
The error message was "could not execute query". This is my own error
message as in
$rs=mysql_query ($sql, $conn) or die ("could not execute query");


change it to
$rs=mysql_query ($sql, $conn) or die ("could not execute query because
".mysql_error() );

The records do exist i deliberately used simple one-word requests as
well. I also
checked i got the same error message by typing in a load of random
letters in the
text field.
The table is called 'music' and the columns are headed 'song' 'folder'
format' 'artist'.

Whether it's relevant to solving the puzzle, i don't know. But, i
stress again that i am
successfully connected to mysql and the database. As, it does
correctly sort and display
the result by the chosen 'order by' command, be it song, folder,
format or artist.


You'd save us all a lot of time if you'd just post the sql statement that's
failing along with the mysql error message.

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@wil lglen.net (it's reserved for spammers)
Jul 17 '05 #10

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

Similar topics

3
1884
by: Nicolae Fieraru | last post by:
Hi All, I try to build an asp page and I try to execute this sql string: dim weight weight = CLng(Request.Form("Weight") strQ = "SELECT * FROM tbFreightPrices WHERE MinWeight < weight" objRS.Open strQ, objConn What happens is that although I get corectly the weight from a form, I can't
10
5635
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I create a single View and specify also in this View the WHERE clause that is common in these stored procedures, I will have the new stored procecures changed to be like:
7
1757
by: binary-nomad | last post by:
Hello, When I do a "AND" in a SQL query, eg. SELECT NAME WHERE SEX="male" AND AGE= "30", MySQL does a sub-search, right? i.e. it does the "WHERE SEX=male" first, and then searches through the list of *those* results to see if AGE=30? Does it do this from left to right? i.e. in the query above, would the table always, and necessarily, get searched for "SEX=male" first, and "AGE=30" second?
3
2246
by: Ptbrady | last post by:
"Order By" fails in form for linked table. -------------- My A2K database has worked well for several years, but now has been split into front-end/back-end and has the following problem. I have a form to access a table which I'll call "NameTable". It has a simple structure: ------------ EmployeeID FirstName (Other fields) (autonumber, primary key) ---------------
9
9598
by: Frederik | last post by:
Hi all, I'm building a C# application that uses a M$ Acces database. In one of the queries I use something like the following: SELECT id FROM mytable WHERE id IN (20, 12, 21, 14) The result is fine, except that the order of the id's is not preserved. It seems to be ordered ascending. How can I keep the order I used as input?
6
9350
by: GSteven | last post by:
(as formerly posted to microsoft.public.access.forms with no result) I've created a continuous form which is based on a straightforward table (ex - customers - 100 records). On the form there is a checkbox with a control source named "MARK" (boolean) from customer table. I can check and uncheck individual records fine. Then I created 2 command buttons named "Select All" and "Deselect All". The Onclick property of these buttons runs code...
7
6338
by: Giles | last post by:
An ASP page outputs data from the query "Select ThisAndThat from comments WHERE pageURL='" & pageURL & "' ORDER BY threadID, datesent" (Access mdb) threadID is a string (OK, I know!), which means that 103 displays before 99. Is there a way to write the SQL query to order them numerically? This would be much easier for me than changing the data type and hunting down every page that INSERTS or UPDATES the db. Thanks, Giles
3
3098
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn =server.createobject("ADODB.connection") objConn.open "DSN=Photo" Dim sqlSELsite,ObjRSSel sqlSELsite = "SELECT Name FROM tblbwday WHERE B'day ="& date() &" " '
3
2704
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Here is my loop and it runs fine: ---------------------------------------------------- sSQL = "SELECT * FROM STORE_ITEMS" Set DataRec = DB.execute(sSQL) if not DataRec.EOF then do while not DataRec.EOF SKU = trim (DataRec("SKU")) ITEM_ID = trim(DataRec("ITEM_ID")) ...
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9200
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
9142
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
8148
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...
0
6022
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
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
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.