473,218 Members | 1,477 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,218 software developers and data experts.

mysql_fetch for aggregate SQL function

I don't understand how I can fetch the result for an aggregate SQL
function. I have a query written like this:

$query = "select max(qno) from answers";
$result = mysql_query($query);

$maxqno = mysql_result($result);

$nextqno = $result + 1;

I initially tried to use the row$ = mysql_fetch_array($result)
function. But, my result isn't an element in an array, corresponding
to a table column in the database. I just simply want to get the
maximum value of "qno" from the table. How do I do it?

Thanks in advance.

Sep 18 '05 #1
4 6601
$query = "select max(qno) from answers";
$result = mysql_query($query); $maxqno = mysql_result($result); $nextqno = $result + 1;


mysql_result() needs a minimum of two arguments: resource and row
number.

Alternatively, use an alias for the aggregate column and get it by
name:

$query = "select max(qno) as maxqno from answers";
$result = mysql_query( $query );

$row = mysql_fetch_array( $result, MYSQL_ASSOC );
print $row[ 'maxqno' ];

---
Steve

Sep 18 '05 #2
$query = "select max(qno) from answers";
$result = mysql_query($query); $maxqno = mysql_result($result); $nextqno = $result + 1;


mysql_result() needs a minimum of two arguments: resource and row
number.

Alternatively, use an alias for the aggregate column and get it by
name:

$query = "select max(qno) as maxqno from answers";
$result = mysql_query( $query );

$row = mysql_fetch_array( $result, MYSQL_ASSOC );
print $row[ 'maxqno' ];

---
Steve

Sep 18 '05 #3
bobkaku wrote:
$query = "select max(qno) from answers";
$result = mysql_query($query);

$maxqno = mysql_result($result);

$nextqno = $result + 1;


Sidetracking a little, are you by any chance re-implementing
auto_increment?

/m
Sep 19 '05 #4
Steve,

Thanks so much. Your solution works like a charm!
Steve wrote:
$query = "select max(qno) from answers";
$result = mysql_query($query);

$maxqno = mysql_result($result);

$nextqno = $result + 1;


mysql_result() needs a minimum of two arguments: resource and row
number.

Alternatively, use an alias for the aggregate column and get it by
name:

$query = "select max(qno) as maxqno from answers";
$result = mysql_query( $query );

$row = mysql_fetch_array( $result, MYSQL_ASSOC );
print $row[ 'maxqno' ];

---
Steve


Sep 20 '05 #5

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

Similar topics

2
by: Claudio Lapidus | last post by:
Hello I would like to know how can I define/create a new aggregate function. I need a custom function that operate on a set of text strings and return a certain string aggregate based on certain...
1
by: sausage31 | last post by:
I have a table as follows.... Device LotID Result1 Result2 Result3 aaa 1 5 10 15 bbb 1 2 4 6 aaa 2 ...
1
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT...
10
by: neb | last post by:
Dear member of the forum, Ms access has built-in aggregate function like: -Sum, Max, First, Avg, ... Is it possible to build user-defined aggregate? (if you have any clue, do not hesitate to...
1
by: Najib Abi Fadel | last post by:
Hi i have an ordered table of dates let's say: 1/1/2004 8/1/2004 15/1/2004 29/1/2004 5/2/2004 12/2/2004
0
by: BillCo | last post by:
just wasted a long time figuring out this and I figure if I post it might save someone some pain! Jet (DAO) will allow you to to use nested aggregate functions like building blocks, e.g.: ...
5
by: BillCo | last post by:
I just wasted a long time figuring out this and I figure if I post it might save someone some pain! Jet (DAO) will allow you to to use nested aggregate functions like building blocks, e.g.: ...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
1
by: Sandro997 | last post by:
Ok. I have a bit of a dilemma here. First, please consider the following function: CREATE OR REPLACE FUNCTION recent_lab(text, labs, treatments) RETURNS float8 AS $BODY$select...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.