...

View Full Version : Code is outputting an incorrect number of articles



moss2076
09-17-2009, 09:49 AM
Hello,

I have a Joomla module which can be set to output 1, 2 or 3 columns and a set number of articles e.g. 2 columns and 4 articles, 3 columns with 7 articles etc etc.

I am trying to add the option for outputting a 4th column, but I am getting incorrect amounts of articles being outputted when I choose 4 columns. For example, if I choose 4 columns with 8 articles, I actaully get 10 articles outputted - 2 of which are repeated.

If I choose up to 3 columns, everything is fine, it is just when I choose a 4th column that incorrect numbers of articles are being displayed.

Check the link, I set 8 articles to be displayed in 4 columns, but I am getting 10 articles displaying - http://www.tomsspecialreserve.co.uk/joomla

I need help to find out what is causing this. Here is my code -

defined('_JEXEC') or die('Restricted access');
$leftColumn = $centreColumn = $rightColumn = $fourthColumn = '';

for($i=0, $col=1, $row=0; $i<$this->news_amount; $i++, $col++)
{
switch($this->news_column)
{
case 2:
if($col == 1)
{
$div_class = 'left_column_class';
}
else
{
$div_class = 'right_column_class';
}
break;

case 3:
if($col == 1)
{
$div_class = 'left_column_class';
}
elseif($col == 2)
{
$div_class = 'centre_column_class';
}
else
{
$div_class = 'right_column_class';
}
break;


case 4:
if($col == 1)
{
$div_class = 'left_column_class';
}
elseif($col == 2)
{
$div_class = 'centre_column_class';
}
elseif($col == 3)
{
$div_class = 'right_column_class';
}
else
{
$div_class = 'fourth_column_class';
}
break;

case 1:
default:
$div_class = 'centre_column_class';
break;
}

if($col == $this->news_column)
{
$col = 0;
$row++;
}

$column = (($row * $this->news_column) + $col) - 1; // adding the -1 makes the array start at 1, not zero! Important!!

/** START LEFT COLUMN **/
if($col == 1 && $this->news_column > 1)
{
if ($this->leftrounded)
{
$leftColumn .= '
<div class="roundedflexable">
<div>
<div>
<div>'."\n";
}
elseif ($this->leftsquaredcorners)
{
$leftColumn .= '
<div class="squared">'."\n";
}

// Add the older stuff
if (isset($news_code_html_tab[$column]))
{
$leftColumn .= $news_code_html_tab[$column];
}

//End Left Column Rounded Corners option
if ($this->leftrounded)
{
$leftColumn .= '
</div>
</div>
</div>
</div>'."\n";
}

//End Left Column Squared Corners option
elseif ($this->leftsquaredcorners) {
$leftColumn .= '
</div>'."\n";
}
}
/** END LEFT COLUMN **/

/** START RIGHT COLUMN **/
elseif($col == 0 && $this->news_column > 1)
{
if ($this->rightrounded)
{
$rightColumn .= '
<div class="roundedflexable">
<div>
<div>
<div>'."\n";
}
elseif ($this->rightsquaredcorners)
{
$rightColumn .= '
<div class="squared">'."\n";
}

if (isset($news_code_html_tab[$column]))
{
$rightColumn .= $news_code_html_tab[$column];
}

if ($this->rightrounded)
{
$rightColumn .= '
</div>
</div>
</div>
</div>'."\n";
}
elseif ($this->rightsquaredcorners)
{
$rightColumn .= '
</div>'."\n";
}
}
/** END RIGHT COLUMN **/

/** START CENTER COLUMN **/
else
{
// No matter what, there's a center column
if ($this->centrerounded)
{
$centreColumn .= '
<div class="roundedflexable">
<div>
<div>
<div>'."\n";
}
elseif ($this->centreroundedfixed)
{
$centreColumn .= '
<div class="gk_round_fixed">
<div>'."\n";
}
elseif ($this->centresquaredcorners)
{
$centreColumn .= '
<div class="squared">'."\n";
}

if (isset($news_code_html_tab[$column]))
{
$centreColumn .= $news_code_html_tab[$column];
}

if ($this->centresquaredcorners) {
$centreColumn .= '
</div>'."\n";
}
elseif ($this->centreroundedfixed) {
$centreColumn .= '
</div>
</div>'."\n";
}
elseif ($this->centrerounded)
{
$centreColumn .= '
</div>
</div>
</div>
</div>'."\n";
}
}
/** END CENTER COLUMN **/

/** START FOURTH COLUMN **/
if($col == 1 && $this->news_column > 3)
{
if ($this->fourthrounded)
{
$fourthColumn .= '
<div class="roundedflexable">
<div>
<div>
<div>'."\n";
}
elseif ($this->fourthsquaredcorners)
{
$fourthColumn .= '
<div class="squared">'."\n";
}

// Add the older stuff
if (isset($news_code_html_tab[$column]))
{
$fourthColumn .= $news_code_html_tab[$column];
}

//End Fourth Column Rounded Corners option
if ($this->fourthrounded)
{
$fourthColumn .= '
</div>
</div>
</div>
</div>'."\n";
}

//End Fourth Column Squared Corners option
elseif ($this->fourthsquaredcorners) {
$fourthColumn .= '
</div>'."\n";
}
}
/** END FOURTH COLUMN **/





}

//Display Output from Left Column here
if (!empty($leftColumn))
{
echo '
<div id="'.$this->left_module_id.'">';
echo $leftColumn;
echo '</div>';
}
//End Left Column
//Display Output from Centre Column here
if (!empty($centreColumn))
{
echo '
<div id="'.$this->centre_module_id.'">';
echo $centreColumn;
echo '</div>'."\n";
}
//Display Output from Right Column here
if (!empty($rightColumn))
{
echo '
<div id="'.$this->right_module_id.'">';
echo $rightColumn;
echo '</div>'."\n";
}
//End Right Column

//Display Output from FOURTH Column here
if (!empty($fourthColumn))
{
echo '
<div id="'.$this->fourth_module_id.'">';
echo $fourthColumn;
echo '</div>'."\n";
}
//End FOURTH Column

moss2076
09-17-2009, 11:05 PM
I think have sorted the problem, just a little tweaking of each columns if statements -
leftcolumn- if($col == 0 && $this->news_column > 0)
rightcolumn- elseif($col == 1 && $this->news_column > 1)
centrecolumn- elseif($col == 2 && $this->news_column > 2)
fourthcolumn- if($col == 3 && $this->news_column > 3)

It seems ok, if I'm wrong, im wrong!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum