RE: [PHP] possible to add a "record number" to a query?
| From: | Jeff Field | Date: | Thu, 13 Jun 2002 18:20:34 +0000 |
| Subject: | RE: [PHP] possible to add a "record number" to a query? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-102017@lists.php.net to get a copy of this message | ||
1) Yes, I'm using MySQL
2) You're right. This is not a PHP question. My apologies to the list!
Thanks for the feedback! I'll give it a try (and the other one in the other
email).
Jeff
> -----Original Message-----
> From: John Holmes [mailto:holmes072000@charter.net]
> Sent: Thursday, June 13, 2002 11:44 AM
> To: jfield@aaaq.com; php-general@lists.php.net
> 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:jfield@aaaq.com]
> > Sent: Thursday, June 13, 2002 10:01 AM
> > To: php-general@lists.php.net
> > 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:php-general@gremlins.com.hk]
> > > Sent: Thursday, June 13, 2002 8:30 AM
> > > To: php-general@lists.php.net
> > > 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
>
>