Posted on: 06/25/05 12:41am
By: DubiousChrisJ
Posted on: 06/25/05 01:35am
By: machinari
$result = DB_query("SELECT sid,title,hits FROM {$_TABLES["stories"]} WHERE (draft_flag = 0) AND (date <= NOW()) AND (Hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY Hits desc LIMIT 10");change LIMIT 10 to LIMIT 1 and you have the most popular story. Throw the output into a block or staticpage. If you want to return the story as well, make it look like this:
$result = DB_query("SELECT sid,title,introtext,bodytext,hits FROM {$_TABLES["stories"]} WHERE (draft_flag = 0) AND (date <= NOW()) AND (Hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY Hits desc LIMIT 1");
Posted on: 06/25/05 01:56am
By: DubiousChrisJ
Posted on: 06/25/05 02:40am
By: machinari
function phpblock_mostpopular() { global $_TABLES; //the rest of your code }
Posted on: 06/25/05 11:44am
By: DubiousChrisJ
function phpblock_mostPopular () { global $_TABLES; $sql = DB_query("SELECT sid,title,hits FROM {$_TABLES["stories"]} WHERE (draft_flag = 0) AND (date <= NOW()) AND (Hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY Hits desc LIMIT 10"); $result = DB_query($sql); $nrows = DB_numRows( $result ); if( $nrows > 0 ) { $string = ''; for( $i = 0; $i < $nrows; $i++ ) { $A = DB_fetchArray( $result ); { $poplist = COM_makeList( $popular, 'list-popular-stories' ); $string .= $poplist . '<br>'; } } $popular = array(); } $popular[] = '<a href="' . COM_buildUrl( $_CONF['site_url'] . '/article.php?story=' . $A['sid'] ) . '">' . $A['title'] . '</a> (' . $A['comments'] . ')'; if( !empty( $popular )) { $poplist = COM_makeList( $popular, 'list-popular-stories' ); $string .= $poplist; DB_query( "UPDATE {$_TABLES['blocks']} SET content = '$string' WHERE name = 'popular_stories'" ); } }
Posted on: 06/25/05 02:18pm
By: machinari
function phpblock_mostPopular() { global $_TABLES; $result = DB_query("SELECT sid,title,hits FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW()) AND (hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY hits desc LIMIT 10"); $nrows = DB_numRows($result); if( $nrows > 0 ){ $string = ''; $popular = array(); for( $i = 0; $i < $nrows; $i++ ){ $A = DB_fetchArray( $result ); $string .= $poplist . '<br>'; $popular[] = '<a href="' . COM_buildUrl( $_CONF['site_url'] . '/article.php?story=' . $A['sid'] ) . '">' . $A['title'] . '</a> (' . $A['hits'] . ')'; } if( !empty( $popular )){ $poplist = COM_makeList( $popular, 'list-popular-stories' ); } } return $poplist; }
Posted on: 06/25/05 04:40pm
By: DubiousChrisJ