RE: [PHP] possible to add a "record number" to a query?

2002-06-13 Thread David Freeman


 > 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  johndoe
 >   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.  

This is an sql question rather than php.

When you get your data include record as one of your select criteria...

Eg. Select record, first, last from my_table

CYA, Dave



--
--
Outback Queensland Internet   
Longreach ** New Web Site Online *
Queensland
Australia W: www.outbackqld.net.au


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




RE: [PHP] possible to add a "record number" to a query?

2002-06-13 Thread Jeff Field

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:[EMAIL PROTECTED]]
> Sent: Thursday, June 13, 2002 11:44 AM
> 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  johndoe
> > > >   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




RE: [PHP] possible to add a "record number" to a query?

2002-06-13 Thread John Holmes

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  johndoe
> > > >   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




RE: [PHP] possible to add a "record number" to a query?

2002-06-13 Thread John Holmes

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  johndoe
> > >   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




Re: [PHP] possible to add a "record number" to a query?

2002-06-13 Thread Chris Hewitt

Jeff,

You don't tell us which database. If its Oracle then there is ROWID. 
Using some sort of record number is good for linking tables as it a 
primary/foreign key, but otherwise why would you want it? If you do not 
have such a field as this at present (and want one), you could always 
add one (ALTER TABLE ADD ColName).

This really is a pure sql question, not relevant to php and this list.

HTH
Chris

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  johndoe
>  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!
>
>Jeff
>



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




RE: [PHP] possible to add a "record number" to a query?

2002-06-13 Thread Jeff Field

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  johndoe
> >   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




Re: [PHP] possible to add a "record number" to a query?

2002-06-13 Thread Jason Wong

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  johndoe
>   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