473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

using mysql count

I have the following query that works in mysql:

select id, order_no, price, count(item_no), sum(price) from production
WHERE item_no = '27714'
group by item_no;

When I setup my query in php, I use:

$query2 = "SELECT id, order_no, price, count(item_no) as count from
production where item_no = '27714";

I keep getting an error in on my php page:

Warning: mysqli_error() expects exactly 1 parameter, 0 given in
c:\Inetpub\wwwroot\production\production_line_dail y.php on line 24
Error in query: SELECT id, order_no, price, count(item_no) as count from
production where item_no = '27714'.

If I remove the count(item_no) as count from the query - it works fine. I
really want to put the count in though. And eventually the sum.

Any help that you can provide is greatly appreciated.

A
Nov 20 '06 #1
3 3073
Auddog wrote:
I have the following query that works in mysql:

select id, order_no, price, count(item_no), sum(price) from production
WHERE item_no = '27714'
group by item_no;

When I setup my query in php, I use:

$query2 = "SELECT id, order_no, price, count(item_no) as count from
production where item_no = '27714";

I keep getting an error in on my php page:

Warning: mysqli_error() expects exactly 1 parameter, 0 given in
c:\Inetpub\wwwroot\production\production_line_dail y.php on line 24
Error in query: SELECT id, order_no, price, count(item_no) as count from
production where item_no = '27714'.

If I remove the count(item_no) as count from the query - it works fine. I
really want to put the count in though. And eventually the sum.

Any help that you can provide is greatly appreciated.

A

It looks like you didn't copy the whole query. It's cut off after '27714. Note
also the missing single quote at the end.

To make it work correctly, copy the complete query - including the "group by
item_no". Without a GROUP BY clause, as MySQL likes to inform you, "mixing of
GROUP columns with non-GROUP columns is illegal".
--
Christoph Burschka
Nov 20 '06 #2

"Christoph Burschka" <ch****************@rwth-aachen.dewrote in message
news:4s************@mid.dfncis.de...
Auddog wrote:
>I have the following query that works in mysql:

select id, order_no, price, count(item_no), sum(price) from production
WHERE item_no = '27714'
group by item_no;

When I setup my query in php, I use:

$query2 = "SELECT id, order_no, price, count(item_no) as count from
production where item_no = '27714";

I keep getting an error in on my php page:

Warning: mysqli_error() expects exactly 1 parameter, 0 given in
c:\Inetpub\wwwroot\production\production_line_dai ly.php on line 24
Error in query: SELECT id, order_no, price, count(item_no) as count from
production where item_no = '27714'.

If I remove the count(item_no) as count from the query - it works fine.
I
really want to put the count in though. And eventually the sum.

Any help that you can provide is greatly appreciated.

A


It looks like you didn't copy the whole query. It's cut off after '27714.
Note
also the missing single quote at the end.

To make it work correctly, copy the complete query - including the "group
by
item_no". Without a GROUP BY clause, as MySQL likes to inform you, "mixing
of
GROUP columns with non-GROUP columns is illegal".
--
Christoph Burschka
Here is my whole query:

<?php

include 'config.php';

/*** create a new mysqli object with default database***/
$connection = mysqli_connect($hostname, $username, $password, $dbname) or
die ("Unable to connect");

//create query
$query = "SELECT distinct item_no FROM production WHERE date '2006-11-11'
group by item_no";

//excute query
$result = mysqli_query($connection, $query) or die ("Error in query: $query.
".mysqli_error());

////create list of variables from query results
while(list($item_no) = @mysqli_fetch_row($result))
{
//print item_no
echo "<b>Item Number:</b$item_no";

//query details about item numbers (from above query)
$query2 = "SELECT id, order_no, serial_no, price, count(item_no) as
count, sum(price) as sum from production where item_no = '$item_no' group by
item_no";

//excute query
$result2 = mysqli_query($connection, $query2) or die ("Error in query:
$query2. ".mysqli_error());

//echo out results
echo "<ul>";
while(list($id, $order_no, $serial_no, $price, $count, $sum) =
@mysqli_fetch_row($result2))
{
echo "<li>$order_no &nbsp;&nbsp;&nbsp;
$serial_no&nbsp;&nbsp;&nbsp;$price<P>";
echo "Item Number Count: <font
color=red>$count</font>&nbsp;&nbsp;Grand total: <font
color=red>$sum</font>";
}
echo "<p>";
echo "</ul>";
}
// close connection
mysqli_close($connection);

?>

When I put back in the 'group by' during the second query, I lose the
ability for each line for the item_no to listed out. I'm trying to get each
item_no to be title and then each serial_no listed out for that item_no. I
would like to get the count and the sum for each item_no.

Hopefully that make sense to everyone. I'm not sure if I should to the work
in the query or in PHP.

A
Nov 20 '06 #3
Auddog wrote:
I have the following query that works in mysql:

select id, order_no, price, count(item_no), sum(price) from production
WHERE item_no = '27714'
group by item_no;

When I setup my query in php, I use:

$query2 = "SELECT id, order_no, price, count(item_no) as count from
production where item_no = '27714";

I keep getting an error in on my php page:

Warning: mysqli_error() expects exactly 1 parameter, 0 given in
c:\Inetpub\wwwroot\production\production_line_dail y.php on line 24
Error in query: SELECT id, order_no, price, count(item_no) as count from
production where item_no = '27714'.

If I remove the count(item_no) as count from the query - it works fine. I
really want to put the count in though. And eventually the sum.

Any help that you can provide is greatly appreciated.

A

If item_no is a numeric type should should NOT have single quotes around
it. Single quotes indicate a string.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 20 '06 #4

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

Similar topics

0
by: madeo | last post by:
hi, i'm looking for some script which would export address labels from a mysql db to pdf ... There's an exapmle, but i'm not able to convert it for using with mysql ... can anybody help? THX...
4
by: Ross Contino | last post by:
Hello to all: I have been searching the web for examples on how to determine a median value in a mySQL table. I have reviewed the article at...
4
by: Japhy | last post by:
Hello, I'm am pulling data from a mysql db and want to use the data to populate a <ul. Here are relavent parts of my code : $wohdate = mysql_result($wohRS,$wohndx,woh_date); $woh_display...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
3
by: auron | last post by:
Hi there, I have a really stupid and banal problem with showing the results of a MySQL query in PHP, preciselly with MySQL count() function that gives to a variable in PHP the result. NOTE:...
27
by: Pom | last post by:
Hello I want to convert a Mysql resulset to a dictionary. I made some code myself, and want to ask you if I do this the right way. def remapmysql(a): return (a, (a)) def test_map():
9
by: =?iso-8859-1?B?Sm/jbyBNb3JhaXM=?= | last post by:
Hi there guys, My doubt is related with MySQL and Transactions (InnoDB) so here it goes: I have a query like this: $query = 'START TRANSACTION; '; $query .= 'UPDATE sections '; $query .=...
0
by: silversubey | last post by:
I am trying to convert mssql triggers to mysql. I am very new to Mysql and would like some help with my code. My queries work but there has to be a more efficient way to write them. I would greatly...
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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...

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.