Re: breaking up records.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You probably better create a sequential array $arr[ month ] = [ 08, ... ]:

$arr = array() ;
while ($slctArchiverow = mysql_fetch_array...  //fetching the array {

    $getMonth = substr($slctArchiverow[diaryMonth],3); //month
    $getDay = substr($slctArchiverow[diaryMonth],0,2); //day
    $arr[$getMonth][] = $getYear ;

}

Now looping is trivial:

while ( list( $month, $list ) = each( $arr ) ) {
    echo $month."<br/>" ;
    $list2 = join( ",", $list ) ;
    echo $list2 ;
    // etc
}

As always, the difficulty is in designing the most suitable array structure.

HTH
Ignatius
____________________________________________
----- Original Message -----
From: "Bruce Levick" <bruce@vivamotion.com>
To: <php-db@lists.php.net>
Sent: Thursday, April 10, 2003 3:31 PM
Subject:  breaking up records.


> Hi Phper's
> I am returning some dates from a rescordset. At Present it displays
> something like this.
>
>
> 10May
> 09Apr
> 09Apr
> 08Apr
> 08Apr
> 08Apr
> 08Apr
>
>
>
> I have broken up the string so I can display the Motnth (May) and the Day
> (10) as I please. I am hoping to be able to display the records like this
> below.
> But am having trouble achieving a while or a do while.
>
>
>
> May
> 10
>
> Apr
> 09, 08, 08, 08, 08
>
>
> I have something like this and of course it is wrong...;0)
>
> // code for displaying the month and the days in that month horizontally
> across
>
> while ($slctArchiverow = mysql_fetch_array...  //fetching the array
>
> // obtaining the month and day from the string
> $getMonth = substr($slctArchiverow[diaryMonth],3); //month
> $getDay = substr($slctArchiverow[diaryMonth],0,2); //day
>
>
> echo $getMonth; //displays the month (May)
> do //display the days that are within May
> {
> echo $getDay; //display the string which is the day of the month
> echo ", ";
> } while ($getMonth == $getMonth); //while the month is equal to May
> echo "<br>";
> }
>
> }
>
> Is it possible to do it in this way or do I need to use if statements for
> each month of the year??
> eg.
> if ($getMonth = May) // and so on for all 12 months.
>
> What are your thoughts??
>
>
> --
> 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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux