You can use

SET @a=0;

Instead of the first SELECT, too.

---John Holmes...

> -----Original Message-----
> From: John Holmes [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 13, 2002 12:44 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: RE: [PHP] possible to add a "record number" to a query?
> 
> You can do it with two queries.
> 
> SELECT @a:=0;
> 
> SELECT @a:=@a+1, * FROM table;
> 
> This would be better taken to a MySQL list, though. Actually, you
never
> said what DB you were using. This works in MySQL.
> 
> ---John Holmes...
> 
> > -----Original Message-----
> > From: Jeff Field [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, June 13, 2002 10:01 AM
> > To: [EMAIL PROTECTED]
> > Subject: RE: [PHP] possible to add a "record number" to a query?
> >
> > Yes, there is a particular reason.  The actual query I do pulls
> > information
> > from two tables and has both ORDER BY and GROUP BY clauses.  The
> > "auto_increment" column (think of the query results as a table) will
> give
> > me
> > the "rank" of the results.  I know how to manipulate the data in PHP
> to
> > accomplish what I need.  I just thought there might be a way in
which
> the
> > query could do it up front.  Sort of like when you want to know how
> many
> > times a particular record exists, you can do a COUNT(*).  I just
want
> the
> > results to basically give me a column in the query that lists the
> results
> > 1,
> > 2, 3, etc.  Make sense?
> >
> > Thanks for your help!
> >
> > Jeff
> >
> > > -----Original Message-----
> > > From: Jason Wong [mailto:[EMAIL PROTECTED]]
> > > Sent: Thursday, June 13, 2002 8:30 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: [PHP] possible to add a "record number" to a query?
> > >
> > >
> > > On Thursday 13 June 2002 20:27, Jeff Field wrote:
> > > > I would like to have a column returned in a query that tells you
> which
> > > > record I'm looking at?  Sort of like an auto_increment?  IOW,
the
> > query
> > > > results would look like:
> > > >
> > > > record   first   last
> > > >
> > > >   1      john    doe
> > > >   2      joe     blow
> > > >   3      carol   fisher
> > > >
> > > > The table only has first and last, but I want the results to
> > > add something
> > > > like record to tell me which record it is.  Thanks for any help!
> > >
> > > Is there any reason why you need/want to do this? Data are stored
> > > in a db in
> > > no particular order. If you want a particular order add an ORDER
> > > BY clause.
> > > If you want 'row' numbers then just fudge it in php -- assign a
> > > row number to
> > > each record you retrieve from the query.
> > >
> > > --
> > > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
> > > Open Source Software Systems Integrators
> > > * Web Design & Hosting * Internet & Intranet Applications
> Development *
> > >
> > > /*
> > > There's such a thing as too much point on a pencil.
> > >           -- H. Allen Smith, "Let the Crabgrass Grow"
> > > */
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to