Jump to content

High commented articles


vividona

Recommended Posts

I think you need to create a PHP script, return the results to an array using mysql_fetch_* and then loop through those results...

 

 

include "db.connection.php";

$query  = "SELECT * FROM bhl_contents INNER JOIN bhl_comments ON bhl_contents.artid = bhl_comments.artid ORDER BY COUNT(bhl_comments.artid) DESC LIMIT 10";
$result = mysql_query($query)or trigger_error("ERROR: " . mysql_error(), E_USER_ERROR);

   while ($row = mysql_fetch_row($result)) :
      echo '<pre>' . print_r($row, true) . '</pre>';
   endwhile;

 

:confused:

Ya, I have my php code and I tried it also

 

$CheckArtisList = $SiteDatabase->dbqueries("SELECT * FROM bhl_contents INNER JOIN bhl_comments ON bhl_contents.artid = bhl_comments.artid ORDER BY COUNT(bhl_comments.artid) DESC LIMIT 10");

		if(!$SiteDatabase->sql_numrows($CheckArtisList) == 1) {
			return false;
		}

		if (isset($_GET['Artid'])) {

		$Artid = intval($_GET['Artid']);

		$ArtiList = $SiteDatabase->dbqueries("SELECT `artid`, `subject`, `body`, `uid`, `username`, `curtime` FROM 
		" . ArticleSystem::BHL_DB_PREFIX . "" . ArticleSystem::BHL_CONT_MGM . " WHERE artid='".$Artid."'");

		}
		echo '<div class="lastarti">
				<div class="nav3">
					Last Articles
				</div>';
		while($row = $SiteDatabase->sql_fetchrow($CheckArtisList))
		{
		$Artid = intval($row['artid']);
		$Sub = $row['subject'];
		$Bod = $row['body'];
		$uid = $row['uid'];

		echo '<ul>
				<li><a href="' . $_SERVER['PHP_SELF'] .'?action=viewarti&artid='.$Artid.'">'.$Sub.'</a> By: <a href="'.$_SERVER['PHP_SELF'].'?action=ubrief&uid='.$uid.'">'.$row['username'].'</a></li>
			</ul>';
		}
		echo '</div>';

I'd say it has more to do with the fact, that a query with aggregate function ( COUNT() ) and no GROUP BY clause will always return but one row

 

SELECT 
  * 
FROM 
  bhl_contents 
CROSS JOIN (
  SELECT 
    artid
    COUNT(*) AS cnt
  FROM
    bhl_comments
  GROUP BY
     artid
) AS sq
USING (artid)
ORDER BY sq.cnt DESC
LIMIT 10

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.