Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa Tarde,
Eu tenho o seguinte código em php.
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
$document =& JFactory::getDocument();
$uri =& JURI::getInstance();
$document->addStyleSheet($uri->root().'modules/mod_ipb_latest/styles/common.css', 'text/css'); // Add stylesheet to the header of the docuemnt.
$topics = $params->get('topics'); // Get number of latest topics to display.
$symbols = $params->get('symbols'); // Get number of tipic title characters to show.
$dateformat = $params->get('dateformat'); // Get date format.
$above = $params->get('above'); // Get data to display ABOVE topics block.
$below = $params->get('below'); // Get data to display BELOW topics block.
$spacer = $params->get('spacer'); // Get spacer height.
$forum_location = $params->get('forum'); // Get forum location.
$option = array(); // Open array with forum database parameters.
$option['driver'] = $params->get('driver'); // Set database driver.
$option['host'] = $params->get('host'); // Set database server.
$option['user'] = $params->get('user'); // Set database user.
$option['password'] = $params->get('password'); // Set database password.
$option['database'] = $params->get('database'); // Set database name.
$option['prefix'] = $params->get('prefix'); // Set database prefix.
$db = & JDatabase::getInstance($option); // Connect to forum database with given parameters.
$row = $db->loadAssocList($db->setQuery("SELECT * FROM ".$option['prefix']."topics ORDER BY last_post DESC LIMIT 0,".$topics)); // Select X latest topics from corresponding table.
$row2 = $db->loadAssocList($db->setQuery("SELECT * FROM ".$option['prefix']."conf_settings WHERE conf_id IN (43,44)"));
$output .= "<span class='aboveText'>".$above."</span><br>"; // Load data above posts block.
for ($i=0;$i<$topics;$i++) // Parse table rows from 0 to X.
{
$proper_time = $row[$i]['last_post'] + $row2[0]['conf_value']6060 + $row2[1]['conf_value']*60; // Adjust time according to IPB settings.
$post_date = gmdate($dateformat, $proper_time); // Get latest post date.
$author_name = $row[$i]['last_poster_name']; // Get last poster name. You may want to add 'iconv' to this variable to convert non-Latin characters to proper encoding.
$topic_title = iconv("UTF-8","ISO-8859-1", $row[$i]['title']); // Get recent topic title. You may want to add 'iconv' to this variable to convert non-Latin characters to proper encoding.
if (($symbols != "") && (strlen($row[$i]['title']) > $symbols))
{
$topic_title = mb_substr($topic_title, 0, $symbols, 'UTF-8')."..."; // Cut topic title to the length given in settings.
}
$output .= "<div id='spacer' style='height: ".$spacer."px'></div><a href='".$forum_location."/index.php?showtopic=".$row[$i]['tid']."&view=getlastpost' class='topicLink'>".$topic_title."</a><br><span class='authorLink'>".JText::_('AUTHOR LABEL').": <a href='".$forum_location."/index.php?showuser=".$row[$i]['last_poster_id']."'>".$author_name."</a></span><br><span class='postDate'>".JText::_('DATE LABEL').": ".$post_date."</span><br>"; // Add new line to resulting output.
}
$output .= "<span class='belowText'>".$below."</span>"; // Load data below posts block.
echo $output; // Display result.
?>
Eu quero adicionar um contador a cada resultado que aparece.Pegando a parte da impressão eu teria:
$output .= "<div id='spacer' style='height: ".$spacer."px'></div> [color="#FF0000"][b](aqui seria aonde quero que apareça um contador a cada linha)[/b][/color] <a href='".$forum_location."/index.php?showtopic=".$row[$i]['tid']."&view=getlastpost' class='topicLink'>".$topic_title."</a><br><span class='authorLink'>".JText::_('AUTHOR LABEL').": <a href='".$forum_location."/index.php?showuser=".$row[$i]['last_poster_id']."'>".$author_name."</a></span><br><span class='postDate'>".JText::_('DATE LABEL').": ".$post_date."</span><br>"; // Add new line to resulting output.
}
Adicionei a seguinte função:
$contador_f = 1;
// Gerando o numero 0 antes dos numeros 1...
if($contador_f < 10) $contador_str = "0".$contador_f;
else $contador_str = $contador_f;
// Acrescentando de 1 em 1 no contador a cada registro
$contador_f++;
E colocando no campo vermelho da impresão o seguinte <strong>$contador_str.</strong> . Porém meu código não funciona, ele até mostra o número 1, mais sem o zero na frente e todas as linhas fica com o 1 na frente, como coloco para que fique 1 na primeira linha, 2 na segunda linha e assim por diante?
Agradeço
Carregando comentários...