Re: [PHP] Re: Get row number from mysql

2002-03-14 Thread Chris Hewitt

Rick,

I agree. Row ids should be for internal database use. SQL frees 
us from needing them. 

Tyler, what order do you want these records returned in? That is what 
goes into the ORDER BY clause. If, for example, it is alphabetical order 
of NAME then use ORDER BY NAME. If it is the order in which people are 
entered into the database then I would either use a sequence and enter 
that into a "person_id" or "sequence" field, alternatively put a 
date/time stamp into a "person_entered_at" field. These result in ORDER 
BY PERSON_ID, ORDER BY SEQUENCE and ORDER BY PERSON_ENTERED_AT respectively.

I'd narrow the question down to "what is it about first person, second 
person and third person that makes them first, second and third.". If we 
know that then I think we may be able to help better.

Hope this helps.

Regards

Chris

Rick Emery wrote:

>The greater question:  Why does irow order matter?  What are you REALLY
>trying to do?
>
>==
>In article <000701c1cb06$3b54f3b0$0101a8c0@nightengale>, 
>[EMAIL PROTECTED] says...
>
>>Hello,
>>
>>How can I get the number of the current row, something like this:
>>
>>>$sql = mysql_query("SELECT * FROM table ORDER BY id DESC");
>>while ($row = mysql_fetch_array($sql)) {
>>$id = $row["id"];
>>$name = $row["name"];
>>print "$current_row_number. $name";
>>}
>>?>
>>I can't just use the id field, because the ID's might not always be 1, 2,
>>
>3,
>
>>4, 5, 6, etc...they could go 1, 2, 4, 5, 8.
>>
>>I need it to look like this:
>>1. first person
>>2. second person
>>3. third person
>>
>>and so on and so forth.
>>
>>Can anyone advise me on how I should do this?
>>
>>thanks,
>>Tyler
>>
>>
>




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




RE: [PHP] Re: Get row number from mysql

2002-03-14 Thread Rick Emery

The greater question:  Why does irow order matter?  What are you REALLY
trying to do?

==
In article <000701c1cb06$3b54f3b0$0101a8c0@nightengale>, 
[EMAIL PROTECTED] says...
> Hello,
> 
> How can I get the number of the current row, something like this:
> 
>  $sql = mysql_query("SELECT * FROM table ORDER BY id DESC");
> while ($row = mysql_fetch_array($sql)) {
> $id = $row["id"];
> $name = $row["name"];
> print "$current_row_number. $name";
> }
> ?>
> I can't just use the id field, because the ID's might not always be 1, 2,
3,
> 4, 5, 6, etc...they could go 1, 2, 4, 5, 8.
> 
> I need it to look like this:
> 1. first person
> 2. second person
> 3. third person
> 
> and so on and so forth.
> 
> Can anyone advise me on how I should do this?
> 
> thanks,
> Tyler
> 
> 

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




Re: [PHP] Re: Get row number from mysql

2002-03-13 Thread Tyler Longren

hmmm, I never thought of that.  Thanks for the help.  ;-)

Tyler

- Original Message -
From: "michael kimsal" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; "Tyler Longren" <[EMAIL PROTECTED]>
Cc: "PHP-General" <[EMAIL PROTECTED]>
Sent: Wednesday, March 13, 2002 9:57 PM
Subject: [PHP] Re: Get row number from mysql


> Tyler Longren wrote:
> > Hello,
> >
> > How can I get the number of the current row, something like this:
> >
> >  > $sql = mysql_query("SELECT * FROM table ORDER BY id DESC");
> > while ($row = mysql_fetch_array($sql)) {
> > $id = $row["id"];
> > $name = $row["name"];
> > print "$current_row_number. $name";
> > }
> > ?>
> > I can't just use the id field, because the ID's might not always be 1,
2, 3,
> > 4, 5, 6, etc...they could go 1, 2, 4, 5, 8.
> >
> > I need it to look like this:
> > 1. first person
> > 2. second person
> > 3. third person
> >
> > and so on and so forth.
> >
> > Can anyone advise me on how I should do this?
> >
> > thanks,
> > Tyler
> >
> >
>
>
>
> Why not just put a counter in there?
>
>   while ($row = mysql_fetch_array($sql)) {
> ++$counter;
>   $id = $row["id"];
>   $name = $row["name"];
>   print "$counter. $name";
>   }
>
>
>
> Michael Kimsal
> http://www.phphelpdesk.com
> PHP support when you need it
> 734-480-9961
>
>
> --
> 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