Jump to content

Recommended Posts

I have the following query string :

 

$query_Recordset2 = sprintf("SELECT DISTINCT ctYear, o, F1, ctComp, ctpYear, ctLvl,ctpup, ctTrainers, ctNotes FROM mainsheet WHERE F1 = %s", GetSQLValueString($colname_Recordset2, "int"));

 

produced by Dreamweaver CS3, but I cannot get it to do what I need.

I have a list of dates eg 2008/9 ,and a list of months but dont want the year duplicated.

 

This is what I have:

YearMonth

2007/8September 07

2007/8October 07

2007/8November 07

2007/8January 08

2007/8August 08

2008/9January 09

 

This is what I need:

YearMonth

2007/8September 07

[/td]October 07

November 07

January 08

2008/9January 09

 

But the DISTINCT command wont work

Link to comment
https://forums.phpfreaks.com/topic/170335-solved-distinct-can-i-use-to-do-this/
Share on other sites

<?php
// Going to load up a list of dates
$dates = array();
$base = strtotime( '1999-12-31' );
for( $i = 0; $i < 200; $i++ ) {
    $offset = rand( 1, 365 * rand( 0, 10 ) ); // day of year
    $offset = $offset * 24 * 60 * 60; // seconds into the year
    $offset = $offset + rand( 0, 24 * 60 * 60 ); // seconds into the day
    $dates[] = date( 'Y-m-d H:i:s', $base + $offset );
}
sort( $dates );

$curYear = null; // keep track of which year we're displaying
echo <<<TABLE
Year      | Rest

TABLE;
foreach( $dates as $d ) {
    $stamp = strtotime( $d );
    $y = sprintf( "%-10s", date( 'Y', $stamp ) );
    // We only display $y as the year IF its not the current year we're tracking
    if( $curYear === $y ) {
        // It's the one we're tracking, so zero it out
        $y = '          ';
    }else{
        $curYear = $y; // Track the new year
    }
    $disp = date( 'F jS, g:i A', $stamp );
echo <<<TABLE
{$y}| {$disp}

TABLE;
}
?>

 

 

so how do i apply it to the following :

<?php do { ?>
        <tr>
          <td width="50"><?php echo $row_Recordset1['ctYear']; ?></td>    <<<< Problem Line
          <td><?php echo $row_Recordset1['ctComp']; ?></td>
          <td width="60"><div align="center"><?php echo $row_Recordset1['ctpYear']; ?></div></td>
          <td width="50"><div align="center"><?php echo $row_Recordset1['ctLvl']; ?></div></td>
          <td width="50"><div align="center"><?php echo $row_Recordset1['ctpup']; ?></div></td>
          <td width="40" align="right"> <a href="vctinfo.php?s=<?php echo $row_Recordset1['o']; ?>">VIEW </a></td>
          <td width="40">- <a href="ectinfo.php?s=<?php echo $row_Recordset1['o']; ?>">EDIT</a></td>
          <td width="40">- <a href="dctinfo.php?o=<?php echo $row_Recordset1['o']; ?>&s=<?php echo $row_Recordset1['F1']; ?>">DEL</a></td>
        </tr>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

<?php 
$curYear = null;
do { 
    $dispYear = $row_Recordset1['ctYear'];
    if( $dispYear === null ) {
        $dispYear = ' ';
    }else{
        $curYear = $dispYear;
    }
?>
        <tr>
          <td width="50"><?php echo $dispYear; ?></td>    <<<< Problem Line
          <td><?php echo $row_Recordset1['ctComp']; ?></td>
          <td width="60"><div align="center"><?php echo $row_Recordset1['ctpYear']; ?></div></td>
          <td width="50"><div align="center"><?php echo $row_Recordset1['ctLvl']; ?></div></td>
          <td width="50"><div align="center"><?php echo $row_Recordset1['ctpup']; ?></div></td>
          <td width="40" align="right"> <a href="vctinfo.php?s=<?php echo $row_Recordset1['o']; ?>">VIEW </a></td>
          <td width="40">- <a href="ectinfo.php?s=<?php echo $row_Recordset1['o']; ?>">EDIT</a></td>
          <td width="40">- <a href="dctinfo.php?o=<?php echo $row_Recordset1['o']; ?>&s=<?php echo $row_Recordset1['F1']; ?>">DEL</a></td>
        </tr>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.