0 ) { $query = $query . ' ORDER BY ' . $sort ; } // query the db $result=mysql_query($query); // count number of results $num=mysql_num_rows($result); // close the db mysql_close(); // display page with results if ( $is_discussion == FALSE ) { $header_title = 'Feedback Index' ; $page_title = 'ARTICLE FEEDBACK' ; } else { $header_title = 'Discussion Index' ; $page_title = 'DISCUSSION' ; } echo_page_head ( $header_title, $page_title . ' INDEX', 83 ) ; echo ('

Instructions

'. "\r\n" ) ; echo (' ' . "\r\n" ); echo ('
' . "\r\n" ) ; echo (' ' . "\r\n" ) ; echo (' ' . "\r\n" ) ; echo ('
' . "\r\n" ) ; if ( $is_discussion == FALSE ) { echo ('
' . "\r\n" ) ; echo (' ' . "\r\n" ) ; } echo (' ' . "\r\n" ) ; echo ('

' . "\r\n" ) ; echo ('' . "\r\n" ) ; echo('' . "\r\n" ) ; echo ('

Index of items received, sorted by ' . $sort_title . "\r\n"); echo('

'. "\r\n" ) ; /* NEW PROBLEM - special treatment needed for discussion items sorted by link (i.e. by topic) if sorted by discussion, we sort by database links, then date this used to be ok, but is not now ok because a discussion topic can be split across non-contiguous links, e.g. ah1D ah3D ah9D and what we will get therefore is one titled item followed by some items that will be part of the discussion followed by the items for a new titled discussion followed later on by untitled items for its own discussion. we can only sort this out by reference to the info files what we do is create an array of bools all set to false to say when a database item is fully done then we loop mark each item in boolean array as processed while is current link when a link changes is there a follow-on link (look in info file) is the follow on link contigous yes - change name of current link and carry on no - keep iterating until find follow on link, and then start writing out again when at end of data if count of processed items indicates some still unprocessed, start the loop again An additional problem: Because of a design mistake, for discussions the sql doen't give us itmes sorted in pure numeric order 15D comes before 1D alphabetically, not after this means we might get a new topic that is untitled, as in the example above - ignore such topics and keep going until a titled one is found */ // create array of flags for items processed for ( $i = 0 ; $i < $num ; $i++ ) { $done[$i] = FALSE ; } // loop to process the items $num_processed = 0 ; $i=-1; $seeking_title = TRUE ; while ($num_processed < $num) { // 1) get next item 2) display it // get next item if ( $sorted_discussion == FALSE ) { $i++ ; $num_processed++ ; $link = mysql_result ($result,$i,"link") ; $title=mysql_result($result,$i,"title"); $timesent=mysql_result($result,$i,"timesent"); $name=mysql_result($result,$i,"name"); if ( $is_discussion == FALSE ) { $author=mysql_result($result,$i,"author"); $article=mysql_result($result,$i,"article"); } } else { if ( $seeking_title ) {//svlog ( 'seeking_title' ) ; // find first non-done title $title = '' ; while ( strlen ($title)== 0 && $i < $num - 1 ) { $i++ ; // start it at -1 if ( $done[$i] == FALSE ) { $title=mysql_result($result,$i,"title"); } } if ( strlen ($title)== 0 && $i == $num - 1 ) // safety, no more titles break ; // while // title found $link = mysql_result ($result,$i,"link") ; $timesent=mysql_result($result,$i,"timesent"); $name=mysql_result($result,$i,"name"); if ( $is_discussion == FALSE ) { $author=mysql_result($result,$i,"author"); $article=mysql_result($result,$i,"article"); } $currlink = $link ; //svlog ( $i . ': $currlink is ' . $currlink ) ; $seeking_title = FALSE ; $done[$i] = TRUE ; $i = -1 ; // next time go back to list start to pick up follow-ons without titles // fall through to display titled item } else { //svlog ( 'seeking untitled ' . $currlink ) ; // not seeking title if ( $i == $num - 1 ) { // no more items //svlog ( 'no more items' ) ; // seek another title $i = -1 ; $seeking_title = TRUE ; continue ; } // find next link same as current link which hasn't been done $title='' ; while ( $i < $num - 1 && strlen ( $title ) == 0 ) { $i++ ; if ( $done[$i] == FALSE ) { $title=mysql_result($result,$i,"title"); $link = mysql_result ($result,$i,"link") ; //svlog ( '$link=' . $link . ' $title=' . $title ) ; if ( strcmp ( $currlink, $link ) == 0 ) { break ; // found one not done yet of the current link } } } // while //svlog ( 'end of search for link same as current link' ) ; // have we got an unprocessed, untitled item with link still current? if ( strlen ( $title) == 0 && strcmp ( $currlink, $link ) == 0 ) { // is ok, get remaining data $timesent=mysql_result($result,$i,"timesent"); $name=mysql_result($result,$i,"name"); if ( $is_discussion == FALSE ) { $author=mysql_result($result,$i,"author"); $article=mysql_result($result,$i,"article"); } } else { // no more of current link // is there a follow-on link (look in info file)? $id = 'A' . $currlink ; $author_code = substr ( $currlink, 0, 2 ) ; $infopath = get_pageinfo_path ($author_code, $id) ; //svlog ( '$infopath is ' . $infopath ) ; $h_info = fopen ( $infopath, 'rb' ) ; if ( $h_info === FALSE ) { // safety if can't open file $i = -1 ; $seeking_title = TRUE ; continue ; } $line1 = fgets ( $h_info, 1024 ) ; // number of lines $line1b = fgets ( $h_info, 1024 ) ; // subject $line2 = fgets ( $h_info, 1024 ) ; // title $line3 = fgets ( $h_info, 1024 ) ; // link back $line4 = fgets ( $h_info, 1024 ) ; fclose ( $h_info ) ; //svlog ( '$line4 ' . $line4 ) ; // is there a follow-on link ? if ( strcmp ( substr ( $line4, 0, 1 ), '0' ) == 0 ) { // no follow-on link, go back to get next title //svlog ( 'no follow-on link' ) ; $i = -1 ; $seeking_title = TRUE ; continue ; } /* Because of a design mistake, links for discussions the sql doen't give us itmes sorted in pure numeric order 15D comes before 1D alphabetically, not after. Search for the follow-on link from the start */ $currlink = substr ( trim($line4), 1 ) ; // removing the leading 'A' and trailing \r\n that is in the info files //svlog ( 'follow-on link is ' . $currlink ) ; $i = -1 ; continue ; } // if link different from last one processed } // else not seking title } // else not sorted discussion // displaying //svlog ( 'displaying' ) ; $done[$i] = TRUE ; // flag displayed $titled = (strlen ( $title ) > 0) ; // remove trailing :00 $len = strlen ( $timesent ) ; if ( $len > 3 ) $timesent = substr ( $timesent, 0, $len - 3 ) ; if ( !$sorted_discussion ) { echo ('

') ; } else if ( $titled ) { echo ('

') ; } else { echo ( '; ' ) ; } echo ("$timesent ' ) ; //svlog ( '$feedback_php_path ' . $feedback_php_path ) ; if ( $sorted_discussion && $titled ) { echo ("Topic: "); echo ("$title"); } else { echo ("$title"); } if ( $titled ) { echo (", f") ; /* normal, following title */ } else /* no title */ if ( $sorted_discussion ) { // echo ( " - comment f" ) ; /* we wanted indented so sub-items can appear under the dated item starting off a discussion thread */ echo ( " f" ) ; /* we wanted indented so sub-items can appear under the dated item starting off a discussion thread */ } else { echo ( "F" ) ; /* we want at start of line in case was not a sub-item and title was ommitted */ } echo ( "rom "); if ($by_contributor) { echo ( "" ) ; } echo ($name) ; if ($by_contributor) { echo ( "" ) ; } echo ( ""); if ( $is_discussion == FALSE ) { if ( $sorted_discussion == FALSE || $titled == TRUE ) { echo ( ', for "') ; if ($by_article ) { echo ( '' ) ; } echo ($article); if ($by_article ) { echo ( '' ) ; } echo ('" by ' ); if ( $by_author ) { echo ( '' ); } echo ( $author ); /* might be Forum code */ if ( $by_author ) { echo ( '' ); } } } if ( $sorted_discussion ) { echo ( " \r\n" ); } else { echo ( "

\r\n" ); } } // while echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo('' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo('

' . "\r\n" ) ; echo('
' . "\r\n" ) ; echo('
' . "\r\n" ) ; echo('
' . "\r\n" ) ; echo('
' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo('

' . "\r\n" ) ; echo('

'); echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo('' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo('
' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo('
' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo(' ' . "\r\n" ) ; echo('' . "\r\n" ) ; ?>