I'm using a premade CMS that I'm not too familiar with. Its really good (Mambo OS), but I need a little bit of help.
I've got a script that is loading a list of objects from a specific database table, and then displaying only 1 item, at random.
Now, what I'm trying to do is get this same script to display the last five added items, with the newest at the top of the list, one on top of another, with a limit of 4 items. Each item needs to have its own, but repeating for each, table layout.
Here is the original code:
PHP Code:
<?php
/// $Id: mod_newsflash3.php,v 1.7 2003/12/03 20:56:34 rcastley Exp $
/**
* newsflash3 Module
* @package Mambo Open Source
* @Copyright (C) 2000 - 2003 Miro International Pty Ltd
* @ All rights reserved
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License : [url]http://www.gnu.org/copyleft/gpl.html[/url]
* @version $Revision: 1.7 $
**/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $gid, $mosConfig_offset;
// load the html drawing class, MUST include the option for components
//require_once( $mainframe->getPath( 'front_html', 'com_newsflash3' ) );
$access = !$mainframe->getCfg( 'shownoauth' );
$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
$database->setQuery( "SELECT COUNT(*) AS numrows"
."\nFROM #__newsflash3"
."\nWHERE published=1"
."\nAND access <= $gid "
."\nAND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now') "
."\nAND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
);
$numrows = $database->loadResult();
if ($numrows > 1) {
mt_srand( (double) microtime()*1000000 );
$flashnum = mt_rand( 0, --$numrows );
} else {
$flashnum = 0;
}
$database->setQuery( "SELECT content"
."\nFROM #__newsflash3"
."\nWHERE published=1"
."\nAND access <= $gid "
."\nAND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now') "
."\nAND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
."\n LIMIT $flashnum,1"
);
$row = null;
if ($database->loadObject( $row )) {
newsflash3_html::Writenewsflash3( $row );
}
class newsflash3_html {
function Writenewsflash3( &$row ) {
?>
<td width="2" rowspan="7"><font color="#F2F2F2" style="font-size: 2px">.</font></td>
<td width="209" height="275" rowspan="7" bgcolor="#8BA2B4" style="padding-top: 6px" valign="top">
<img src="<?php echo $mosConfig_live_site;?>/templates/default/images/edcor.jpg" width="209" height="5" style="margin-bottom: 31px">
<center><img src="<?php echo $mosConfig_live_site;?>/templates/default/images/editorial.jpg" width="191" height="89" style="border: 4px solid white; margin-bottom: 18px"></center>
<p class="hfeat" style="font-size: 10px; color: white; margin-left: 11px; margin-right: 11px; margin-bottom: 28px">
<?php echo $row->content; ?>
</p></td>
<?php
}
}
?>
Ok, and here is an example of another script in the same cms, that does what I am trying to do (gets items, displayes them in order), but I can't seem to get my *version* of the hacked code to work.
PHP Code:
<?php
//Section Latest News Module//
// $Id: mod_SectionLatestNews.php,v 1.0b 2004/01/20 by Tony Lightfoot based upon mod_latestnews.php by rcastley Exp $
/**
* Section Latest News Module
* @package Mambo Open Source
* @Copyright (C) 2000 - 2003 Miro International Pty Ltd
* @ All rights reserved
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License : [url]http://www.gnu.org/copyleft/gpl.html[/url]
* @version $Revision: 1.0b $
**/
/**
* Section Latest News Module
*Displays the news queued to be published.
*/
// following line is to prevent direct access to this script via the url
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $mosConfig_offset;
$count = @$params->count ? intval( $params->count ) : 5;
$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
$query = "SELECT c.id, c.name, a.id, a.title, a.sectionid, a.catid"
. "\nFROM #__content AS a, #__categories AS c"
. "\nWHERE ( c.id = a.catid AND a.state='1' AND a.sectionid > '0' AND a.checked_out='0' )"
. "\n AND (a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '$now')"
. "\n AND (a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '$now')"
. ($catid ? "\n AND a.catid='$catid'" : '')
. "\nORDER BY created DESC LIMIT $count";
// initialise the query in the $database connector
// this translates the '#__' prefix into the real database prefix
$database->setQuery( $query );
// retrieve the list of returned records as an array of objects
$rows = $database->loadObjectList();
// cycle through the returned rows displaying them in a table
// with links to the content item
// escaping in and out of php is now permitted
?>
<table cellpadding="1" cellspacing="1" border="0">
<?php foreach ($rows as $row) { ?>
<tr>
<td valign="top"><img border="0" src="<?php echo $mosConfig_live_site;?>/images/M_images/arrow.png"></td>
<td><strong><a href="<?php echo sefRelToAbs("index.php?option=content&task=view&id=$row->id"); ?>"><?php echo $row->title;?></a></strong><br><a href="<?php echo sefRelToAbs("index.php?option=content&task=category§ionid=$row->sectionid&id=$row->catid"); ?>"><?php echo $row->name;?></a></td>
</tr>
<?php
}
?>
</table>
Could anyone help me please?
Any help at all is greatly appreciated. Thanks.