yep, good point.  thanks. =)

----- Original Message -----
From: "Rick Emery" <[EMAIL PROTECTED]>
To: "'David Fudge'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, February 13, 2002 12:43 PM
Subject: RE: [PHP-DB] First and Last Record Query


> Why are you iterating through the array?  Why not just:
>
>         $start_id = $row[0];
>         $end_id = $row[count($row)-1];
>
> -----Original Message-----
> From: David Fudge [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, February 13, 2002 11:40 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] First and Last Record Query
>
>
> well, if you're using an array, you could use a for like this:
>
> $row = mysql_fetch_row($result);
> for( $i=0;$i<count($row);$i++ )
> {
>     if( $i==0 )
>         $start_id = $row[$i];
>     elseif( $i == (count($row)-1) )
>         $end_id = $row[$i];
> }
>
>
> ----- Original Message -----
> From: "Rankin, Randy" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, February 13, 2002 12:32 PM
> Subject: [PHP-DB] First and Last Record Query
>
>
> > Does anyone know how to grab only the first and last record of a query.
> >
> > I have a table named periods with two fields, period_id and period_name.
> The
> > user will select a start period and an end period from a drop down list,
> > assigning $start_period and $end_period variables based on the period
id.
> If
> > I run this query:
> >
> > Select period_name
> > from periods
> > where period_id between '$start_period_id' and '$end_period_id'
> > order by period_id
> >
> > An array is returned which could include one or more records, depending
> upon
> > the user selection. I would like to grab the first and last record in
the
> > array so that the final result would be to echo something like "This
> report
> > is from $start_period through $end_period".
> >
> > Hope that makes sense ...
> >
> > Thanks in advance for any help.
> >
> > Randy Rankin
> >
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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

Reply via email to