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:
// 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?