473,796 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't use GROUP BY from PHP

I'm connecting to an access database and I would like the query to
return results grouped on a particular column. When I try the following
query, I get this error back from PHP:
DB Error: syntax Error

"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID = $loc_ID
GROUP BY Manufacturer"

Iposted this question on a PHP list and someone there suggested that SQl
does not allow this to happen unless its part of an aggregate statement.
Is this true? Is there a way around this?
TIA
Jun 6 '06 #1
9 1480
Lorenzo Thurman wrote:
I'm connecting to an access database and I would like the query to
return results grouped on a particular column. When I try the following
query, I get this error back from PHP:
DB Error: syntax Error

"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID = $loc_ID
GROUP BY Manufacturer"

Iposted this question on a PHP list and someone there suggested that SQl
does not allow this to happen unless its part of an aggregate statement.
Is this true? Is there a way around this?
TIA


It's possibe the $loc_id is not being parsed as its value. Remember,
strings are surrounded by quotes, dates by #, and everything else by
nothing. Here's how I might write your statement in Access

"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID = '" & _
loc_ID & "' GROUP BY Manufacturer"

or

"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID = """ &
loc_ID & """ GROUP BY Manufacturer"

This assumes loc_id is a string.
Jun 6 '06 #2
In article <PM************ ****@newsread1. news.pas.earthl ink.net>,
salad <oi*@vinegar.co m> wrote:
Lorenzo Thurman wrote:
I'm connecting to an access database and I would like the query to
return results grouped on a particular column. When I try the following
query, I get this error back from PHP:
DB Error: syntax Error

"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID = $loc_ID
GROUP BY Manufacturer"

Iposted this question on a PHP list and someone there suggested that SQl
does not allow this to happen unless its part of an aggregate statement.
Is this true? Is there a way around this?
TIA


It's possibe the $loc_id is not being parsed as its value. Remember,
strings are surrounded by quotes, dates by #, and everything else by
nothing. Here's how I might write your statement in Access

"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID = '" & _
loc_ID & "' GROUP BY Manufacturer"

or

"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID = """ &
loc_ID & """ GROUP BY Manufacturer"

This assumes loc_id is a string.


Thanks for the reply. Here's what I get when I use getDebugInfo():
SELECT HardwareInstall ations.Manufact urer, CountOfModel, Model, Platform
FROM HardwareInstall ations WHERE LocationID = 7 GROUP BY
HardwareInstall ations.Manufact urer [nativecode=3700 0 [Microsoft][ODBC
Microsoft Access Driver] You tried to execute a query that does not
include the specified expression 'CountOfModel' as part of an aggregate
function.]

LocationID being parsed correctly. It just cant get around this
aggregate thingy.
Jun 6 '06 #3
You can't use GROUP BY with SELECT *.

Select specific columns and include all of them as GROUP BY, SUM(), COUNT(),
or something.
Jun 6 '06 #4
salad <oi*@vinegar.co m> wrote in
news:PM******** ********@newsre ad1.news.pas.ea rthlink.net:
Lorenzo Thurman wrote:
I'm connecting to an access database and I would like the query
to return results grouped on a particular column. When I try the
following query, I get this error back from PHP:
DB Error: syntax Error

"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID =
$loc_ID GROUP BY Manufacturer"

Iposted this question on a PHP list and someone there suggested
that SQl does not allow this to happen unless its part of an
aggregate statement. Is this true? Is there a way around this?
TIA


It's possibe the $loc_id is not being parsed as its value.


You obvioiusly know nothing about PHP.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jun 7 '06 #5
David W. Fenton wrote:
salad <oi*@vinegar.co m> wrote in
news:PM******** ********@newsre ad1.news.pas.ea rthlink.net:

Lorenzo Thurman wrote:
I'm connecting to an access database and I would like the query
to return results grouped on a particular column. When I try the
following query, I get this error back from PHP:
DB Error: syntax Error

"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID =
$loc_ID GROUP BY Manufacturer"

Iposted this question on a PHP list and someone there suggested
that SQl does not allow this to happen unless its part of an
aggregate statement. Is this true? Is there a way around this?
TIA


It's possibe the $loc_id is not being parsed as its value.

You obvioiusly know nothing about PHP.

That is correct. Neither do the people on the PHP list. It appears
Rick Wannal spotted the error.
Jun 7 '06 #6
On Tue, 06 Jun 2006 19:13:21 GMT, "Rick Wannall"
<wa*****@notado main.de> wrote:

Rick is right. First work out the kinks in the Access query designer,
then implement in your code. The query designer would have pointed out
the error of your ways :-)

-Tom.
You can't use GROUP BY with SELECT *.

Select specific columns and include all of them as GROUP BY, SUM(), COUNT(),
or something.


Jun 7 '06 #7
salad <oi*@vinegar.co m> wrote in
news:oh******** *******@newsrea d2.news.pas.ear thlink.net:
David W. Fenton wrote:
salad <oi*@vinegar.co m> wrote in
news:PM******** ********@newsre ad1.news.pas.ea rthlink.net:
Lorenzo Thurman wrote:

I'm connecting to an access database and I would like the query
to return results grouped on a particular column. When I try the
following query, I get this error back from PHP:
DB Error: syntax Error

"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID =
$loc_ID GROUP BY Manufacturer"

Iposted this question on a PHP list and someone there suggested
that SQl does not allow this to happen unless its part of an
aggregate statement. Is this true? Is there a way around this?
TIA

It's possibe the $loc_id is not being parsed as its value.


You obvioiusly know nothing about PHP.


That is correct. Neither do the people on the PHP list. It
appears Rick Wannal spotted the error.


No, the error was a Jet SQL error, not a PHP error.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jun 7 '06 #8
David W. Fenton wrote:
salad <oi*@vinegar.co m> wrote in
news:oh******** *******@newsrea d2.news.pas.ear thlink.net:

David W. Fenton wrote:
salad <oi*@vinegar.co m> wrote in
news:PM***** ***********@new sread1.news.pas .earthlink.net:
Lorenzo Thurman wrote:
>I'm connecting to an access database and I would like the query
>to return results grouped on a particular column. When I try the
>followin g query, I get this error back from PHP:
>DB Error: syntax Error
>
>"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID =
>$loc_ID GROUP BY Manufacturer"
>
>Iposted this question on a PHP list and someone there suggested
>that SQl does not allow this to happen unless its part of an
>aggregat e statement. Is this true? Is there a way around this?
>TIA

It's possibe the $loc_id is not being parsed as its value.

You obvioiusly know nothing about PHP.


That is correct. Neither do the people on the PHP list. It
appears Rick Wannal spotted the error.

No, the error was a Jet SQL error, not a PHP error.

No. The error was a programmer error. It was a PHP error because there
was a Jet error that existed because of programmer error. Rick Wannal
spotted the programmer error that will fix the Jet error that will not
be result in a PHP error.
Jun 7 '06 #9
salad <oi*@vinegar.co m> wrote in
news:3h******** *********@newsr ead1.news.pas.e arthlink.net:
David W. Fenton wrote:
salad <oi*@vinegar.co m> wrote in
news:oh******** *******@newsrea d2.news.pas.ear thlink.net:
David W. Fenton wrote:

salad <oi*@vinegar.co m> wrote in
news:PM**** ************@ne wsread1.news.pa s.earthlink.net :

>Lorenzo Thurman wrote:
>
>>I'm connecting to an access database and I would like the
>>query to return results grouped on a particular column. When I
>>try the following query, I get this error back from PHP:
>>DB Error: syntax Error
>>
>>"SELECT * FROM HardwareInstall ationsSummary WHERE LocationID =
>>$loc_ID GROUP BY Manufacturer"
>>
>>Iposted this question on a PHP list and someone there
>>suggest ed that SQl does not allow this to happen unless its
>>part of an aggregate statement. Is this true? Is there a way
>>around this? TIA
>
>It's possibe the $loc_id is not being parsed as its value.

You obvioiusly know nothing about PHP.

That is correct. Neither do the people on the PHP list. It
appears Rick Wannal spotted the error.


No, the error was a Jet SQL error, not a PHP error.


No. The error was a programmer error. It was a PHP error because
there was a Jet error that existed because of programmer error.
Rick Wannal spotted the programmer error that will fix the Jet
error that will not be result in a PHP error.


The PHP part of the code was correct. It would have produced no
error had the SQL been correct.

It was not a PHP error -- it was PHP reporting an error that came
from the ODBC driver.

Calling it a "programmer error" is ludicrous, since had it been a
PHP syntax error or a SQL error, it would still have been typed by
the programmer involved.

My point in drawing this out is that the answers that suggested
treating the construction of the dynamic SQL string the same way you
would do it in VBA were ignorant of the way PHP parses variables
inline in strings, and missed the point entirely.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jun 8 '06 #10

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

Similar topics

2
14170
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip Smarty-2.6.7.tar.gz on a system running WindowsXP SP2. Apache and PHP tested out fine. After adding Smarty, I ran the following http://localhost/testphp.php
3
15769
by: moon | last post by:
Hi all, Im trying to execute this statement in SQL Plus but am getting the error not a single-group group function. My code is below. To explain what Im trying to get at, I want to return the total grade for g.grade that has been multiplied by its appropriate weight that it carries towards the total grade. SELECT g.section_id, g.student_id, g.grade_type_code, SUM((AVG(g.grade)*30/100+AVG(g.grade)
1
17102
by: Tamer Higazi | last post by:
Hi! I have problems creating joins between tables and to limit rows for a specified clolumn. I have 2 tables! employees departments I face the problems with the GROUP BY clause and i don't get it handled solving that problem. Neither with oracle sql or SQL1999 syntax!
0
1489
by: Randell D. | last post by:
Folks, I have two tables - one called parent, the other called group. table group is made up of ID,parentID,groupHash and groupName. table parent is made up of ID,title,group1Hash,group2Hash,group3Hash (and other columns) Each of the group hashes in table parent correspond to a group hash in table group (ie parent.group1Hash exists in/as group.groupHash and
13
2141
by: Leo | last post by:
Hi I had asekd previously a question qith regards to running a DLL file from ASP. It was not running for me. Bo error returned, nothing, Just an empty string (when it should have not been empty). I created a .vbs file and put it in the same directory as the .asp file on the web. The same exact code. It runs fine. Soon as I call the asp file, it still does nothing. Would anyone have an idea as to why the .asp has no ability to run this...
5
8589
by: Bayla Frankl | last post by:
Hi all, I am a little stumped. I have a query I am trying to run to retrieve the last Progress Note record from the database for the current patient so that the therapists can see the last note while typing the current note. This seemed to be simple to me, since I figured, you take the max(TxDate) that exists before my current date and all should be fine. I tried that and got all the records that exist for this patient before that date.
12
25301
by: Bill Moran | last post by:
Hey all. I've hit an SQL problem that I'm a bit mystified by. I have two different questions regarding this problem: why? and how do I work around it? The following query: SELECT GCP.id, GCP.Name FROM Gov_Capital_Project GCP,
10
2186
by: Extremest | last post by:
I know there are ways to make this a lot faster. Any newsreader does this in seconds. I don't know how they do it and I am very new to c#. If anyone knows a faster way please let me know. All I am doing is quering the db for all the headers for a certain group and then going through them to find all the parts of each post. I only want ones that are complete. Meaning all segments for that one file posted are there. using System;
2
2002
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some reason now it is not finding ones that are single posts. Here is an example of a header for a single. (Ask the Dust ) - "atd-ftc-repack.nfo" www.ctjes.com (1/1) (1/1) at the end means it is part 1 of a 1 part post. Any help would be...
52
6359
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10239
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...
0
10019
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
9057
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
7555
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
6796
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
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
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
3
2928
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.