Welcome, Guest. Please login or register.
March 21, 2010, 03:41:30 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
110600 Posts in 15971 Topics by 9314 Members
Latest Member: Linuxkommunist
* Home Help Search Login Register
+  WebsiteBaker Community Forum
|-+  English
| |-+  Help & Support (Moderators: Argos, BerndJM)
| | |-+  overview of news posts and comments
Pages: [1] Go Down Print
Author Topic: overview of news posts and comments  (Read 112 times)
danest

Offline Offline

Posts: 17


« on: February 05, 2010, 02:53:47 AM »

I'll try to be more specific about my question:
I'd like to make a code page with a table listing the last 30 news posts and/or comments to news posts, ordered by descenting dates with the following columns:
Time, username, news post header, comment header.
In case it is a news post, comment header should be empty.
Something like the tables in this forum. My site has maybe 150 news posts divided on maybe 30 pages, and I would like to get an overview of what might be going on in there.
Is it possible? MySQL? How? Can anybody help?
Site: www.hidethedecline. eu
Logged
danest

Offline Offline

Posts: 17


« Reply #1 on: February 05, 2010, 10:47:51 AM »

I can make an SQL statement that retrieves something, but I need to make it work correctly by joining fields from different tables. Im not very good at that. Anybody willing to help here?

I have copied some code and modified, but its all just amateurs mess, just to see if it works:
Code:
// Specify the Group(id) you want to read the news from or 0 for all groups
$group = 0;       

// Specify number of newsitems                       
$limit=30;

// Specify read more text
$readmore = "Read more";       

// Specify Older news text
$oldernews = "Older items";       

// Query for obtaining stuff
$query = "SELECT * FROM ".TABLE_PREFIX."mod_news_comments ORDER BY comment_ID DESC LIMIT 0, 30;";

// Query for all groups ;)
if ($group<1 ) {
  $query = "SELECT * FROM ".TABLE_PREFIX."mod_news_comments ORDER BY comment_ID DESC LIMIT 0, 30;";
}

// No changes needed here, maybe for output!

global $database;

$result = $database->query($query);
$total = $result->numRows();       // how many items are there?

if ($total>200) {                                // at least 2 needed for 2 news items
  $data = $result->fetchRow() ;    // get left item
  $data2 = $result->fetchRow() ;  // get right item
  echo '<table width=100% border=1>';
  echo '<tr><td width=50%><b>'.$data['title'].'</b></td><td></td></tr>';
  echo '<tr><td>'.$data['content_short'].'</td><td></td></tr>';
  echo '<tr><td><a href="'.WB_URL.PAGES_DIRECTORY.$data['link'].PAGE_EXTENSION.'">'.$readmore.'</a></td><td></td></tr>';
  echo '<tr><td></td><td></td></tr>';
  echo '<tr><td></td><td></td></tr>';
  echo '<tr><td></td><td></td></tr>';
  echo '<tr><td></td><td></td></tr>';
  echo '<tr><td></td><td></td></tr>';
  echo '<tr><td></td><td width=50%><b>'.$data2['title'].'</b></td></tr>';
  echo '<tr><td></td><td>'.$data2['content_short'].'</td></tr>';
  echo '<tr><td></td><td><a href="'.WB_URL.PAGES_DIRECTORY.$data2['link'].PAGE_EXTENSION.'">'.$readmore.'</a></td></tr>';
  echo '</table>';
}

// Next show the rest
if ($total>0) {                                // are there any left?
echo '<br><br><table><tr><td colspan=2><b>'.$oldernews.'</b></td></tr>';
echo '<tr><td>'.$data['commented_when'].'</td><td>Comment title</td></tr>';
while ($data = $result->fetchRow()) {
  echo '<tr><td>'.strftime( "%d-%m-%Y",$data['posted_when']).'</td>';
  echo '<td><a href="'.WB_URL.PAGES_DIRECTORY.$data['link'].PAGE_EXTENSION.'">'.$data['title'].'</a></td></tr>';
}
echo '</table>';
}

It produces the output you see here: http://www.hidethedecline.eu/pages/links/test-sql.php.
In addition to the problems if making the correct query with joins to other tables, this output has wrong dates (all identical) and the links doesn't work.
Can anybody help, or do you know somebody who can?
Logged
danest

Offline Offline

Posts: 17


« Reply #2 on: February 05, 2010, 12:33:07 PM »

I don't know what happened. The News module disapperaed from the database, so all the posts are gone. Is there any way I can re-install the news module without having to re-install the entire site?
Logged
Pages: [1] Go Up Print 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!