Ir para conteúdo
Fórum Script Brasil
  • 0

Dúvida de como listas data por Mês


Hayllon Prata

Pergunta

Olá tenho o seguinte recordset:

// Get the transaction recordset

$rsagenda = $tNGs->getRecordset("agenda");

$row_rsagenda = mysql_fetch_assoc($rsagenda);

$totalRows_rsagenda = mysql_num_rows($rsagenda);

$data = array (1=> 'Janeiro', 2=> 'Fevereiro', 3=> 'Março', 4=> 'Abril', 5=> 'Maio', 6=> 'Junho', 7=> 'Julho', 8=> 'Agosto', 9=> 'Setembro', 10=> 'Outubro', 11=> 'Novembro', 12=> 'Dezembro');

e quero listar a data do mês pelo nome e não sei o que preciso fazer... e preciso muito de ajuda, no momento esta listando assim:

<?php echo date('m', strtotime($row_agenda['data'])); ?>

Link para o comentário
Compartilhar em outros sites

4 respostass a esta questão

Posts Recomendados

  • 0

Não entendi. Se você quer listar pelo nome basta usar um echo dod elementos da matriz diretamente, sem processamento algum já que os elementos do array são os nomes dos meses.

<?php
echo $data[$i]; //$i é o inteiro correspondente ao mês, por exemplo, se $i = 1, a resposta será Janeiro
?>

Link para o comentário
Compartilhar em outros sites

  • 0

então, na verdade eu estou fazendo uma agenda de eventos para um Dj, e vou ser bem sincero não manjo muito de php estou usaando a developer mas estou entendendo aos poucos o PHP ^^

vou postar meu código abaixo para ver se entende, tenho um formulario para postar as datas e quero exibir em vez do numero o nome do mês, Obrigado, segue:

<?php require_once('../../Connections/mit.php'); ?>

<?php

//MX Widgets3 include

require_once('../../includes/wdg/WDG.php');

?><?php

//initialize the session

if (!isset($_SESSION)) {

session_start();

}

// ** Logout the current user. **

$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";

if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){

$logoutAction .=&". htmlentities($_SERVER['QUERY_STRING]);

}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']==true")){

//to fully log out a visitor we need to clear the session varialbles

$_SESSION['MM_Username] = NULL;

$_SESSION['MM_UserGroup'] = NULL;

$_SESSION['PrevUrl'] = NULL;

unset($_SESSION['MM_Username']);

unset($_SESSION['MM_UserGroup']);

unset($_SESSION['PrevUrl']);

$logoutGoTo = "../../index.php";

if ($logoutGoTo) {

header("Location: $logoutGoTo");

exit;

}

}

?>

<?php

// Load the common classes

require_once('../../includes/common/KT_common.php');

?>

<?php

if (!isset($_SESSION)) {

session_start();

}

$MM_authorizedUsers = "";

$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page

function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {

// For security, start by assuming the visitor is NOT authorized.

$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.

// Therefore, we know that a user is NOT logged in if that Session variable is blank.

if (!empty($UserName)) {

// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.

// Parse the strings into arrays.

$arrUsers = Explode(",", $strUsers);

$arrGroups = Explode(",", $strGroups);

if (in_array($UserName, $arrUsers)) {

$isValid = true;

}

// Or, you may restrict access to only certain users based on their username.

if (in_array($UserGroup, $arrGroups)) {

$isValid = true;

}

if (($strUsers == "") && true) {

$isValid = true;

}

}

return $isValid;

}

$MM_restrictGoTo = "../restrito.php";

if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {

$MM_qsChar = "?";

$MM_referrer = $_SERVER['PHP_SELF'];

if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";

if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)

$MM_referrer .= "?" . $QUERY_STRING;

$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck= . urlencode($MM_referrer);

header("Location: ". $MM_restrictGoTo);

exit;

}

?>

<?php

// Load the tNG classes

require_once('../../includes/tng/tNG.inc.php');

// Make a transaction dispatcher instance

$tNGs = new tNG_dispatcher("../../");

// Make unified connection variable

$conn_mit = new KT_connection($mit, $database_mit);

// Start trigger

$formValidation = new tNG_FormValidation();

$tNGs->prepareValidation($formValidation);

// End trigger

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {

case "text":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "long":

case "int":

$theValue = ($theValue != "") ? intval($theValue) : "NULL";

break;

case "double":

$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

break;

case "date":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "defined":

$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

break;

}

return $theValue;

}

}

//Mês

$mes = array (1=> 'Janeiro', 2=> 'Fevereiro', 3=> 'Março', 4=> 'Abril', 5=> 'Maio', 6=> 'Junho', 7=> 'Julho', 8=> 'Agosto', 9=> 'Setembro', 10=> 'Outubro', 11=> 'Novembro', 12=> 'Dezembro');

mysql_select_db($database_mit, $mit);

$query_agenda = "SELECT *,date_format(data,'%d-%m-%Y')as data FROM agenda ORDER BY data DESC";

$agenda = mysql_query($query_agenda, $mit) or die(mysql_error());

$row_agenda = mysql_fetch_assoc($agenda);

$totalRows_agenda = mysql_num_rows($agenda);

// Make an insert transaction instance

$ins_agenda = new tNG_insert($conn_mit);

$tNGs->addTransaction($ins_agenda);

// Register triggers

$ins_agenda->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");

$ins_agenda->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);

$ins_agenda->registerTrigger("END", "Trigger_Default_Redirect", 99, "index.php");

// Add columns

$ins_agenda->setTable("agenda");

$ins_agenda->addColumn("data", "DATE_TYPE", "POST", "data");

$ins_agenda->addColumn("evento", "STRING_TYPE", "POST", "evento");

$ins_agenda->addColumn("local", "STRING_TYPE", "POST", "local");

$ins_agenda->setPrimaryKey("id", "NUMERIC_TYPE");

// Execute all the registered transactions

$tNGs->executeTransactions();

// Get the transaction recordset

$rsagenda = $tNGs->getRecordset("agenda");

$row_rsagenda = mysql_fetch_assoc($rsagenda);

$totalRows_rsagenda = mysql_num_rows($rsagenda);

$data = array (1=> 'Janeiro', 2=> 'Fevereiro', 3=> 'Março', 4=> 'Abril', 5=> 'Maio', 6=> 'Junho', 7=> 'Julho', 8=> 'Agosto', 9=> 'Setembro', 10=> 'Outubro', 11=> 'Novembro', 12=> 'Dezembro');

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wdg="http://ns.adobe.com/addt">

<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<title>Painel de Controle</title>

<style type="text/css">

<!--

body {

margin-left: 0px;

margin-top: 0px;

margin-right: 0px;

margin-bottom: 0px;

}

.style1 {

color: #FFFFFF;

font-weight: bold;

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 12px;

}

.style5 {

font-size: 12px;

font-family: Verdana, Arial, Helvetica, sans-serif;

font-weight: bold;

}

a:link {

color: #FFFFFF;

text-decoration: none;

}

a:visited {

text-decoration: none;

color: #FFFFFF;

}

a:hover {

text-decoration: none;

color: #000000;

}

a:active {

text-decoration: none;

color: #000000;

}

a:link.alterar {

color:#000000;

font-size:12px;

font:Verdana, Arial, Helvetica, sans-serif;

}

a:visited.alterar {

color:#000000;

font-size:12px;

font:Verdana, Arial, Helvetica, sans-serif;

}

a:hover.alterar {

color:#0099FF;

font-size:12px;

font:Verdana, Arial, Helvetica, sans-serif;

}

a:active.alterar {

text-decoration: none;

color: #000000;

font:Verdana, Arial, Helvetica, sans-serif;

}

.style7 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }

.style9 {

font-size: 13px;

font-weight: bold;

}

.style10 {color: #00FFCC}

.style11 {font-size: 13px; font-weight: bold; color: #00FFCC; }

.style12 {color: #FFFFFF}

-->

</style>

<link href="../../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />

<script src="../../includes/common/js/base.js" type="text/javascript"></script>

<script src="../../includes/common/js/utility.js" type="text/javascript"></script>

<script src="../../includes/skins/style.js" type="text/javascript"></script>

<?php echo $tNGs->displayValidationRules();?><script type="text/javascript" src="../../includes/common/js/sigslot_core.js"></script>

<script type="text/javascript" src="../../includes/wdg/classes/MXWidgets.js"></script>

<script type="text/javascript" src="../../includes/wdg/classes/MXWidgets.js.php"></script>

<script type="text/javascript" src="../../includes/wdg/classes/Calendar.js"></script>

<script type="text/javascript" src="../../includes/wdg/classes/SmartDate.js"></script>

<script type="text/javascript" src="../../includes/wdg/calendar/calendar_stripped.js"></script>

<script type="text/javascript" src="../../includes/wdg/calendar/calendar-setup_stripped.js"></script>

<script src="../../includes/resources/calendar.js"></script>

</head>

<body>

<table width="800" height="236" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td height="50"><table width="800" height="50" border="0" cellpadding="0" cellspacing="0">

<tr>

<td bgcolor="#0099FF"><img src="http://www.agenciamit.com.br/painel_sites/topo.jpg" alt="" width="800" height="50" /></td>

</tr>

</table></td>

</tr>

<tr>

<td height="30"><table width="800" height="30" border="1" cellpadding="0" cellspacing="0" bordercolor="#0099FF">

<tr>

<td><table width="88" border="0" cellspacing="0" cellpadding="0">

<tr>

<td><div align="right"><span class="style5"><a href="../categorias.php" class="alterar">&lt;- VOLTAR</a></span></div></td>

</tr>

</table></td>

<td width="99" bgcolor="#FF0000"><div align="center" class="style1"><a href="<?php echo $logoutAction ?>">SAIR</a></div></td>

</tr>

</table></td>

</tr>

<tr>

<td height="106"><table width="800" height="38" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#000000">

<tr>

<td bgcolor="#000000"><div align="center" class="style5"><span class="style12">CONTE&Uacute;DO ATUAL</span><br />

</div></td>

</tr>

<tr>

<td class="style7"><br />

<table width="600" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#666666">

<tr>

<td>&nbsp;

<?php

echo $tNGs->getErrorMsg();

?>

<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">

<table width="350" cellpadding="2" cellspacing="0" class="KT_tngtable">

<tr>

<td class="KT_th"><label for="data">Data:</label></td>

<td><input name="data" id="data" value="<?php echo KT_formatDate($row_rsagenda['data]); ?>" size="18" wdg:mondayfirst="true" wdg:subtype="Calendar" wdg:mask="<?php echo $KT_screen_date_format; ?>" wdg:type="widget" wdg:singleclick="true" wdg:restricttomask="yes" />

<?php echo $tNGs->displayFieldHint("data");?> <?php echo $tNGs->displayFieldError("agenda", "data"); ?> </td>

</tr>

<tr>

<td class="KT_th"><label for="evento">Evento:</label></td>

<td><input type="text" name="evento" id="evento" value="<?php echo KT_escapeAttribute($row_rsagenda['evento']); ?>" size=50" />

<?php echo $tNGs->displayFieldHint("evento");?> <?php echo $tNGs->displayFieldError("agenda", "evento"); ?> </td>

</tr>

<tr>

<td class="KT_th"><label for="local">Local:</label></td>

<td><input name="local" type="text" id="local" value="<?php echo KT_escapeAttribute($row_rsagenda['local]); ?>" size="50" />

<?php echo $tNGs->displayFieldHint("local");?> <?php echo $tNGs->displayFieldError("agenda", "local"); ?> </td>

</tr>

<tr class="KT_buttons">

<td colspan="2"><input type="submit" name="KT_Insert1" id="KT_Insert1" value="INSERIR AGENDA" />

</td>

</tr>

</table>

</form>

<table border="1" align="center" cellspacing="10">

<tr>

<?php

do { // horizontal looper version 3

?>

<td><table width="200" border="0" align="center" cellpadding="2" cellspacing="0">

<tr>

<th width="82" scope="col"><?php echo date('d', strtotime($row_agenda['data'])); ?></th>

<th width=110" scope="col"><?php echo date('m', strtotime($row_agenda['data])); ?></th>

</tr>

<tr>

<td colspan="2"><?php echo $row_agenda['evento']; ?></td>

</tr>

<tr>

<td colspan=2"><?php echo $row_agenda['local]; ?></td>

</tr>

</table></td>

<?php

$row_agenda = mysql_fetch_assoc($agenda);

if (!isset($nested_agenda)) {

$nested_agenda= 1;

}

if (isset($row_agenda) && is_array($row_agenda) && $nested_agenda++ % 1==0) {

echo "</tr><tr>";

}

} while ($row_agenda); //end horizontal looper version 3

?>

</tr>

</table>

<p>&nbsp;</p></td>

</tr>

</table>

<br />

<br /></td>

</tr>

</table></td>

</tr>

<tr>

<td height="50"><table width="800" height="50" border="0" cellpadding="0" cellspacing="0">

<tr>

<td bgcolor="#0099FF"><img src="http://www.agenciamit.com.br/painel_sites/footer.jpg" width="800" height="50" /></td>

</tr>

</table></td>

</tr>

</table>

</body>

</html>

<?php

mysql_free_result($agenda);

?>

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...