|
91
|
Programación / Bases de Datos / ¿Como mostrar mis datos de base de datos en el calendario?
|
en: 1 Mayo 2017, 21:31 pm
|
Hola, soy novato en php y mysql y me gustaría hacer un calendario php mysql, ví el tutorial de https://www.codexworld.com/build-event-calendar-using-jquery-ajax-php/ y me gustó mucho, me arrancó bien pero me gustaría que demostrara mis datos de la DB en el calendario. Mi tabla es la siguiente: fecha | tipoevento | otro | materia | asunto | tarea | evento |
Yo modifiqué el código: <?php /* * Function requested by Ajax */ if(isset($_POST['func']) && !empty($_POST['func'])){ switch($_POST['func']){ case 'getCalender': getCalender($_POST['year'],$_POST['month']); break; case 'getEvents': getEvents($_POST['date']); break; default: break; } }
/* * Get calendar full HTML */ function getCalender($year = '',$month = '') { $dateYear = ($year != '')?$year:date("Y"); $dateMonth = ($month != '')?$month:date("m"); $date = $dateYear.'-'.$dateMonth.'-01'; $currentMonthFirstDay = date("N",strtotime($date)); $totalDaysOfMonth = cal_days_in_month(CAL_GREGORIAN,$dateMonth,$dateYear); $totalDaysOfMonthDisplay = ($currentMonthFirstDay == 7)?($totalDaysOfMonth):($totalDaysOfMonth + $currentMonthFirstDay); $boxDisplay = ($totalDaysOfMonthDisplay <= 35)?35:42; ?> <div id="calender_section"> <h2> <a href="javascript:void(0);" onclick="getCalendar('calendar_div','<?php echo date("Y",strtotime($date.' - 1 Month')); ?>','<?php echo date("m",strtotime($date.' - 1 Month')); ?>');"><<</a> <select name="month_dropdown" class="month_dropdown dropdown"><?php echo getAllMonths($dateMonth); ?></select> <select name="year_dropdown" class="year_dropdown dropdown"><?php echo getYearList($dateYear); ?></select> <a href="javascript:void(0);" onclick="getCalendar('calendar_div','<?php echo date("Y",strtotime($date.' + 1 Month')); ?>','<?php echo date("m",strtotime($date.' + 1 Month')); ?>');">>></a> </h2> <div id="event_list" class="none"></div> <div id="calender_section_top"> <ul> <li>Domingo</li> <li>Lunes</li> <li>Martes</li> <li>Miércoles</li> <li>Jueves</li> <li>Viernes</li> <li>Sábado</li> </ul> </div> <div id="calender_section_bot"> <ul> <?php $dayCount = 1; for($cb=1;$cb<=$boxDisplay;$cb++){ if(($cb >= $currentMonthFirstDay+1 || $currentMonthFirstDay == 7) && $cb <= ($totalDaysOfMonthDisplay)){ //Current date $currentDate = $dateYear.'-'.$dateMonth.'-'.$dayCount; $eventNum = 0; //Include db configuration file include 'dbConfig.php'; //Get number of events based on the current date $result = $db->query("SELECT fecha FROM 1esoacalendar WHERE date = '".$currentDate."' AND status = 1"); $eventNum = $result->num_rows; //Define date cell color if(strtotime($currentDate) == strtotime(date("Y-m-d"))){ echo '<li date="'.$currentDate.'" class="grey date_cell">'; }elseif($eventNum > 0){ echo '<li date="'.$currentDate.'" class="light_sky date_cell">'; }else{ echo '<li date="'.$currentDate.'" class="date_cell">'; } //Date cell echo '<span>'; echo $dayCount; echo '</span>'; //Hover event popup echo '<div id="date_popup_'.$currentDate.'" class="date_popup_wrap none">'; echo '<div class="date_window">'; echo '<div class="popup_event">Eventos ('.$eventNum.')</div>'; echo ($eventNum > 0)?'<a href="javascript:;" onclick="getEvents(\''.$currentDate.'\');">Ver eventos</a>':''; echo '</div></div>'; echo '</li>'; $dayCount++; ?> <?php }else{ ?> <li><span> </span></li> <?php } } ?> </ul> </div> </div>
<script type="text/javascript"> function getCalendar(target_div,year,month){ $.ajax({ type:'POST', url:'functions.php', data:'func=getCalender&year='+year+'&month='+month, success:function(html){ $('#'+target_div).html(html); } }); } function getEvents(date){ $.ajax({ type:'POST', url:'functions.php', data:'func=getEvents&date='+date, success:function(html){ $('#event_list').html(html); $('#event_list').slideDown('slow'); } }); } function addEvent(date){ $.ajax({ type:'POST', url:'functions.php', data:'func=addEvent&date='+date, success:function(html){ $('#event_list').html(html); $('#event_list').slideDown('slow'); } }); } $(document).ready(function(){ $('.date_cell').mouseenter(function(){ date = $(this).attr('date'); $(".date_popup_wrap").fadeOut(); $("#date_popup_"+date).fadeIn(); }); $('.date_cell').mouseleave(function(){ $(".date_popup_wrap").fadeOut(); }); $('.month_dropdown').on('change',function(){ getCalendar('calendar_div',$('.year_dropdown').val(),$('.month_dropdown').val()); }); $('.year_dropdown').on('change',function(){ getCalendar('calendar_div',$('.year_dropdown').val(),$('.month_dropdown').val()); }); $(document).click(function(){ $('#event_list').slideUp('slow'); }); }); </script> <?php }
/* * Get months options list. */ function getAllMonths($selected = ''){ $options = ''; for($i=1;$i<=12;$i++) { $value = ($i < 10)?'0'.$i:$i; $selectedOpt = ($value == $selected)?'selected':''; $options .= '<option value="'.$value.'" '.$selectedOpt.' >'.date("F", mktime(0, 0, 0, $i+1, 0, 0)).'</option>'; } return $options; }
/* * Get years options list. */ function getYearList($selected = ''){ $options = ''; for($i=2015;$i<=2025;$i++) { $selectedOpt = ($i == $selected)?'selected':''; $options .= '<option value="'.$i.'" '.$selectedOpt.' >'.$i.'</option>'; } return $options; }
/* * Get events by date */ function getEvents($date = ''){ //Include db configuration file include 'dbConfig.php'; $eventListHTML = ''; $date = $date?$date:date("Y-m-d"); //Get events based on the current date $result = $db->query("SELECT * FROM 1esoacalendar WHERE date = '".$date."' AND fecha = 1"); if($result->num_rows > 0){ $eventListHTML = '<h2>Eventos en '.date("l, d M Y",strtotime($date)).'</h2>'; $eventListHTML .= '<ul>'; while($row = $result->fetch_assoc()){ $eventListHTML .= '<li>'.$row['tipoevento'].'</li>'; $eventListHTML .= '<li>'.$row['otro'].'</li>'; $eventListHTML .= '<li>'.$row['materia'].'</li>'; $eventListHTML .= '<li>'.$row['asunto'].'</li>'; $eventListHTML .= '<li>'.$row['tarea'].'</li>'; $eventListHTML .= '<li>'.$row['evento'].'</li>'; } $eventListHTML .= '</ul>'; } echo $eventListHTML; } ?>
pero no me va, el calendario arranca pero no me muestra los eventos. Atentamente IVÁN HEREDIA PLANAS. Gracias.
|
|
|
92
|
Programación / Bases de Datos / Error en el calendario php mysql
|
en: 18 Abril 2017, 23:08 pm
|
Hola, he cogido un código que he visto y lo he modificado a mi gusto, pero tengo unos problemas. Tengo el calendario y un formulario que hice yo, que añade los datos en la DB. El calendario no me muestra los datos guardados en la DB, es decir me lo muestra pero sin los datos, y tendría que guardarlo en la fecha correspondiente (que yo la añada) pero lo guarda en la fecha actual, y si añado más de una, también. No entiendo que pasa. Yo pensé que era por este código: // si el día del evento coincide lo marcamos y guardamos la información if($event_day == $day) { $marked = true; $events_list = $event; break; }
Que hay una variable cuya variable es $day= $start_date->format('j');
Creo que lo que esta diciendo el código es que añada los datos en el día actual y yo lo quiero dependiendo de lo que ponga en el input databox tipo date, no sería así $day=$start_date->$_POST['materiabox'];
pero lo hice y me da error. Código: <!-- Codigo javascript --> <script> $(function dias_seleccionados() { var events = ['15-1-2011', '02-1-2011', '17-1-2011', '17-2-2011']; $( "#datepicker" ).datepicker({ beforeShowDay: function(date) { var current = $.datepicker.formatDate('dd-m-yy', date); return jQuery.inArray(current, events) == -1 ? [true, ''] : [true, 'ui-state-hover', 'ui-state-highlight']; } }); }); </script> <script type='text/javascript'> document.getElementById('tipoEventos').addEventListener('change', function(){ var valor = this.value; // Si el valor elegido del select == otro, habilitar la caja de texto. if(valor === 'otro'){ var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } }); </script> <style> .btnmás { background-color:transparent; border: transparent; font-size: 30px; cursor: pointer; border-radius: 1000px; font-family: segoe script; } </style> <style> .textbox { background: transparent; font-family: segoe script; border: none; } </style> <style> .btn1 { background: #e09410; background-image: -webkit-linear-gradient(top, #e09410, #ffb700); background-image: -moz-linear-gradient(top, #e09410, #ffb700); background-image: -ms-linear-gradient(top, #e09410, #ffb700); background-image: -o-linear-gradient(top, #e09410, #ffb700); background-image: linear-gradient(to bottom, #e09410, #ffb700); -webkit-border-radius: 60; -moz-border-radius: 60; border-radius: 10px; border: none; font-size:15px; font-family: segoe script; padding: 1px 20px 2px 5px; text-decoration: none; width: 1px; height: 30px; cursor: pointer; } .btn1:hover { background: #ffcc00; text-decoration: none; } </style> <style> .btn2 { background: #e09410; background-image: -webkit-linear-gradient(top, #e09410, #ffb700); background-image: -moz-linear-gradient(top, #e09410, #ffb700); background-image: -ms-linear-gradient(top, #e09410, #ffb700); background-image: -o-linear-gradient(top, #e09410, #ffb700); background-image: linear-gradient(to bottom, #e09410, #ffb700); -webkit-border-radius: 60; -moz-border-radius: 60; border-radius: 10px; border: none; font-size:15px; font-family: segoe script; padding: 1px 120px 2px 5px; text-decoration: none; width: 1px; height: 30px; cursor: pointer; } .btn2:hover { background: #ffcc00; text-decoration: none; } </style> <style> .btn3 { background: #e09410; background-image: -webkit-linear-gradient(top, #e09410, #ffb700); background-image: -moz-linear-gradient(top, #e09410, #ffb700); background-image: -ms-linear-gradient(top, #e09410, #ffb700); background-image: -o-linear-gradient(top, #e09410, #ffb700); background-image: linear-gradient(to bottom, #e09410, #ffb700); -webkit-border-radius: 60; -moz-border-radius: 60; border-radius: 10px; border: none; font-size:15px; font-family: segoe script; padding: 1px 170px 2px 5px; text-decoration: none; width: 1px; height: 30px; cursor: pointer; } .btn3:hover { background: #ffcc00; text-decoration: none; } </style> <style> .btn4 { background: #e09410; background-image: -webkit-linear-gradient(top, #e09410, #ffb700); background-image: -moz-linear-gradient(top, #e09410, #ffb700); background-image: -ms-linear-gradient(top, #e09410, #ffb700); background-image: -o-linear-gradient(top, #e09410, #ffb700); background-image: linear-gradient(to bottom, #e09410, #ffb700); -webkit-border-radius: 60; -moz-border-radius: 60; border-radius: 10px; border: none; font-size:15px; font-family: segoe script; padding: 1px 120px 2px 5px; text-decoration: none; width: 1px; height: 30px; cursor: pointer; } .btn4:hover { background: #ffcc00; text-decoration: none; } </style> <style type='text/css'> #tipoEventos { border: inset; border-color: orange; opacity: 0.8; font-family: sgoe script; font-size: 14px; } #tipoEventos option { font-family: sgoe script; color: #333; font-size: 1.5em; } #otroTipoEventos { display: none; border: inset; border-color: orange; opacity: 0.8; font-family:segoe script; font-size: 14px; position: center; } </style> <?php // Establecer el idioma al Español para strftime(). setlocale( LC_TIME, 'spanish' ); // Si no se ha seleccionado mes, ponemos el actual y el año $month = isset( $_GET[ 'month' ] ) ? $_GET[ 'month' ] : date( "Y-n" ); $week = 1; for ( $i=1;$i<=date( 't', strtotime( $month ) );$i++ ) { $day_week = date( 'N', strtotime( $month.'-'.$i ) ); $calendar[ $week ][ $day_week ] = $i; if ( $day_week == 7 ) $week++; } ?>
<!DOCTYPE html>
<html>
<head> <title>Calendario PHP/HTML5</title> <script src='https://www.google.com/recaptcha/api.js'></script> <style type="text/css">body{margin:0;font-family:Lato;}ul,li{list-style-type:none; margin:0;padding:0;}.calendar{padding:30px;}.calendar .day{background:#ecf0f1;border-bottom:2px solid #bdc3c7;float:left;margin:3px;position:relative;height:120px;width:120px;}.day.marked{background:#3498db;border-color:#2980b9;}.day .day-number{color:#7f8c8d;left:5px;position:absolute;top:5px;}.day.marked .day-number{color:white;}.day .events{color:white;margin:29px 7px 7px;height:78px;overflow-x:hidden;overflow-y:hidden;}.day .events h5{margin:0 0 5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width:100%;}.day .events strong,.day .events span{display:block;font-size:11px;}.day .events ul{}.day .events li{} </style> </head> <body style="background-image: url('imagenes/fondo ies calvia proyecto.jpg'); background-repeat: no-repeat; background-position: all; background-attachment: fixed; background-size: cover;"> <div class="calendar"> <?php
$mysqli = new mysqli('censurado', 'censurado', 'censurado', 'censurado');
if ( $mysqli->connect_errno ) { die( $mysqli->mysqli_connect_error() ); }
$result = $mysqli->query('SELECT fecha, tipoevento, otro, materia, asunto, tarea, evento FROM 1esoacalendar');
if( !$result ) die( $mysqli->error );
$events = array();
while($rows = $result->fetch_assoc()) { $start_date = new DateTime($rows['fecha_inicio']); $end_date = new DateTime($rows['fecha_fin']); $day = $start_date->format('j');
$events[$day][] = array( 'start_hour' => $start_date->format('G:i a'), 'end_hour' => $end_date->format('G:i a'), 'team_code' => $rows['cod_equipo'], 'description' => $rows['descripcion'], 'tipoevento' => $rows['tipoEventos'], 'otro' => $rows['otroTipoEventos'], 'materia' => $rows['materiabox'], 'asunto' => $rows['asuntobox'], 'tarea' => $rows['tareabox'], 'evento' => $rows['eventobox'], ); }
$datetime = new DateTime();
// mes en texto $txt_months = array( 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'septiembre', 'Octubre', 'Noviembre', 'Diciembre' );
$month_txt = $txt_months[$datetime->format('n')-1];
// ultimo dia del mes $month_days = date('j', strtotime("last day of"));
echo '<h1>' . $month_txt . '</h1>';
foreach(range(1, $month_days) as $day) { $marked = false; $events_list = array();
foreach($events as $event_day => $event) { // si el dia del evento coincide lo marcamos y guardamos la informacion if($event_day == $day) { $marked = true; $events_list = $event; break; } }
echo ' <div class="day' . ($marked ? ' marked' : '') . '"> <strong class="day-number">' . $day . '</strong> <div class="events"><ul>';
foreach($events_list as $event) { echo '<li> <div> <strong>Tipo de evento:</strong> <span>' . $event['tipoevento'] . '</span> </div>
<div> <strong>Otro:</strong> <font>' . $event['otro'] . '</font> </div> <div> <strong>Materia:</strong> <font>' . $event['materia'] . '</font> </div> <div> <strong>Asunto:</strong> <font>' . $event['asunto'] . '</font> </div> <div> <strong>Tarea:</strong> <font>' . $event['tarea'] . '</font> </div> <div> <strong>Evento:</strong> <font>' . $event['evento'] . '</font> </div> </li>'; }
echo '</ul></div> </div>'; } ?> </div> <form id="demo" align="center" action="añadirevento.php" method="post"> <font face="segoe script" size="+6" color="#333333">Insertar eventos</font> <br> <font face="segoe script" size="+1" color="#333333">Data:</font> <input type="date" name="databox" style="border: inset;border-color: orange; opacity: 0.8; font-family: segoe script; font-size:14px;" required> <br> <font face="segoe script" size="+1" color="#333333">Tipo de evento:</font> <select name="tipoEventos" id="tipoEventos" style="border: inset;border-color: orange; opacity: 0.8; font-family: segoe script; font-size: 14px;" required> <option value="null" selected disabled><font face="segoe script" size="+1">---Eligir tipo de evento---</font></option> <option value="deberes"><font face="segoe script" size="+1">Deberes</font></option> <option value="trabajos"><font face="segoe script" size="+1">Trabajos</font></option> <option value="controles"><font face="segoe script" size="+1">Controles</font></option> <option value="salidas"><font face="segoe script" size="+1">Salidas</font></option> <option value="vacaciones"><font face="segoe script" size="+1">Vacaciones</font></option> <option value="otro"><font face="segoe script" size="+1">Otro...</font></option> </select> <script type='text/javascript'> document.getElementById('tipoEventos').addEventListener('change', function(){ var valor = this.value; // Si el valor elegido del select == otro, habilitar la caja de texto. if(valor === 'otro'){ var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'inherit'; var display = document.getElementById('cambiartexto'); display.innerHTML='Asunto:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Evento:'; } }); </script> <script type='text/javascript'> document.getElementById('tipoEventos').addEventListener('change', function(){ var valor = this.value; if(valor === 'vacaciones'){ var display = document.getElementById('cambiartexto'); display.innerHTML='Asunto:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Evento:'; } if (valor == 'salidas') { var display = document.getElementById('cambiartexto'); display.innerHTML='Asunto:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Evento:'; } if (valor == 'deberes') { var display = document.getElementById('cambiartexto'); display.innerHTML='Materia:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Tarea:'; } if (valor == 'trabajos') { var display = document.getElementById('cambiartexto'); display.innerHTML='Materia:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Tarea:'; } if (valor == 'controles') { var display = document.getElementById('cambiartexto'); display.innerHTML='Materia:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Tarea:'; } }); </script> <script> document.getElementById('tipoEventos').addEventListener('change', function(){ var valor= this.value; if (valor=='deberes') { var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } if (valor=='trabajos') { var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } if (valor=='controles') { var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } if (valor=='salidas') { var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } if (valor=='vacaciones') { var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } }); </script> <script> document.getElementById('tipoEventos').addEventListener('change', function(){ var valor = this.value; if(valor === 'otro'){ var cambiarmateriabox1 = document.getElementById("materia"); cambiarmateriabox1.setAttribute("name","asuntobox"); var cambiartareabox1 = document.getElementById("tarea"); cambiartareabox1.setAttribute("name","eventobox"); } }); </script> <script> document.getElementById('tipoEventos').addEventListener('change', function(){ var valor = this.value; if(valor === 'vacaciones'){ var cambiarmateriabox2 = document.getElementById("materia"); cambiarmateriabox2.setAttribute("name","asuntobox"); var cambiartareabox2 = document.getElementById("tarea"); cambiartareabox2.setAttribute("name","eventobox"); } if (valor == 'salidas') { var cambiarmateriabox3 = document.getElementById("materia"); cambiarmateriabox3.setAttribute("name","asuntobox"); var cambiartareabox3 = document.getElementById("tarea"); cambiartareabox3.setAttribute("name","eventobox"); } if (valor == 'deberes') { var cambiarmateriabox4 = document.getElementById("materia"); cambiarmateriabox4.setAttribute("name","materiabox"); var cambiartareabox4 = document.getElementById("tarea"); cambiartareabox4.setAttribute("name","tareabox"); } if (valor == 'trabajos') { var cambiarmateriabox5 = document.getElementById("materia"); cambiarmateriabox5.setAttribute("name","materiabox"); var cambiartareabox5 = document.getElementById("tarea"); cambiartareabox5.setAttribute("name","tareabox"); } if (valor == 'controles') { var cambiarmateriabox6 = document.getElementById("materia"); cambiarmateriabox6.setAttribute("name","materiabox"); var cambiartareabox6 = document.getElementById("tarea"); cambiartareabox6.setAttribute("name","tareabox"); } }); </script> <input type="text" name="otroTipoEventos" id="otroTipoEventos" style="position:relative; left:880px; top: -30px; display: none;" disabled> <br> <font face="segoe script" size="+1" color="#333333" id="cambiartexto">Materia:</font> <br> <input type="text" name="materiabox" style="border:inset; border-color: orange; opacity: 0.8; font-family: segoe script; font-size: 14px;" oncut="return false" onpaste="return false" oncut="return false" placeholder=" Escribe aquí..." required id="materia"> <br> <font face="segoe script" size="+1" color="#333333" id="cambiartextarea">Tarea:</font> <br> <textarea name="tareabox" style="border:inset; border-color: orange; opacity: 0.8; font-family: segoe script; font-size:14px;" cols="50" rows="10" placeholder="Escribe aquí..." required id="tarea"></textarea> <br> <center> <div class="g-recaptcha" data-sitekey="6Lc87RwUAAAAAJNPN8mZSXyelFGykTxpJ3rx3WQ9"></div> </center> <br> <input type="submit" name="Enviar" value="Guardar datos" class="btn2"> <input type="reset" name="eliminar" class="btn3" value="Limpiar formulario"> </form> </body> </html>
Yo no sé si es eso, pero no se cual es el error. Me sale así: https://drive.google.com/file/d/0B6mh5xJztGS9NUtPdDF2NllReTg/view?usp=sharingBase de datos: https://drive.google.com/open?id=0B6mh5xJztGS9UUlkeUcycGVOUUkGracias
|
|
|
93
|
Programación / Desarrollo Web / Como hacer en una etiqueta <option> una función dentro de <select>
|
en: 17 Marzo 2017, 23:09 pm
|
Hola estoy haciendo una etiqueta select que cuando clique en otro... me salga otra caja devtexto pero hice un onclick en option de otro... y no me va pero no se como se hace. <select name="Tipo de eventos" style="border: inset;border-color: orange; opacity: 0.8; font-family: segoe script; font-size: 14px;"> <option value="---Eligir tipo de evento---" selected onchange="populate(this.id,'otro')"><font face="segoe script" size="+1" color="#333333">---Eligir tipo de evento---</font></option> <option value="Deberes"><font face="segoe script" size="+1" color="#333333">Deberes</font></option> <option value="Trabajos"><font face="segoe script" size="+1" color="#333333">Trabajos</font></option> <option value="Salidas"><font face="segoe script" size="+1" color="#333333">Salidas</font></option> <option value="Vacaciones"><font face="segoe script" size="+1" color="#333333">Vacaciones</font></option> <option value="Otro..." id="otro"><font face="segoe script" size="+1" color="#333333">Otro...</font></option> </select> <input type="text" name="Tipo de eventos2" style="display: none; border: inset;border-color: orange; opacity: 0.8; font-family:segoe script; font-size: 14px;" id="otro">
Gracias.
|
|
|
94
|
Programación / PHP / Cambiar mes por mes en calendario php.
|
en: 27 Febrero 2017, 16:49 pm
|
Hola,tengo un calendario php. <?php $week = 1;
for ($i=1; $i<=date('t'); $i++) {
$day_week = date('N', strtotime(date('Y-m').'-'.$i)); $calendar [$week] [$day_week] = $i;
if ($day_week == 7) { $week++; }; } ?> <?php $Nombre_mes = date("F"); $Nombre_año = date("Y"); ?> <!DOCTYPE html> <html> <head> </head>
<body>
<table border="4" id="calendar" style="border: solid; border-color: #B45F04; background-color: #F7D358; font-family: segoe script;"> <thead> <tr> <td><center><input type="button" name="previousbutton" style="width:40px; cursor: pointer;" value="<<"></center></td> <td colspan="5"><center><b><?php echo $Nombre_mes." de ".$Nombre_año; ?></b></center></td> <td><center><input type="button" name="nextbutton" style="width:60px; cursor: pointer;" value=">>"></center></td> </tr> <tr> <td><center><b>Lunes</b></center></td> <td><center><b>Martes</b></center></td> <td><center><b>Miércoles</b></center></td> <td><center><b>Jueves</b></center></td> <td><center><b>Viernes</b></center></td> <td><center><b>Sábado</b></center></td> <td><center><b>Domingo</b></center></td> </tr> </thead> <tbody> <?php foreach($calendar as $days) :?> <tr> <?php for ($i=1;$i<=7;$i++) :?> <td> <?php echo isset($days[$i]) ? $days[$i] : ''; ?> </td> <?php endfor; ?> </tr> <?php endforeach ?> </tbody> </table> </body> </html>
Tengo arriba dos botones para cambiar los meses (mes por mes, y cuando se acaba los meses, cambia a un año más y atrás) y lo tengo que hacer pero no se como hacerlo, me ayudé de un vídeo pero no me funciona, no sé como buscarlo en google, y lo busco pero no encuentro. Gracias
|
|
|
95
|
Programación / PHP / Hola, mi calendario php, da un fallo en los días. (solo muestra el primer día)
|
en: 26 Febrero 2017, 21:28 pm
|
La solución fue: <?php $week = 1;
for ($i=1; $i<=date('t'); $i++) {
$day_week = date('N', strtotime(date('Y-m').'-'.$i)); $calendar [$week] [$day_week] = $i;
if ($day_week == 7) { $week++; }; } ?> <?php $Nombre_mes = date("F"); $Nombre_año = date("Y"); ?> <!DOCTYPE html> <html> <head> <script> function goLastMonth(month, year){ if (month == 1) { --year; month = 12; } document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+month+"&year="+year; }
function goNextMonth(month, year){ if (month == 12) { ++year month = 1; } document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+month+"&year"+year; } </script> </head>
<body>
<table border="4" id="calendar" style="border: solid; border-color: #B45F04; background-color: #F7D358; font-family: segoe script;"> <thead> <tr> <td><center><input type="button" name="previousbutton" onclick="goLastMonth(<?php echo $month.",".$year ?>)" style="width:40px; cursor: pointer;" value="<<"></center></td> <td colspan="5"><center><b><?php echo $Nombre_mes." de ".$Nombre_año; ?></b></center></td> <td><center><input type="button" name="nextbutton" onclick="goNextMonth(<?php echo $month.",".$year ?>)" style="width:60px; cursor: pointer;" value=">>"></center></td> </tr> <tr> <td><center><b>Lunes</b></center></td> <td><center><b>Martes</b></center></td> <td><center><b>Miércoles</b></center></td> <td><center><b>Jueves</b></center></td> <td><center><b>Viernes</b></center></td> <td><center><b>Sábado</b></center></td> <td><center><b>Domingo</b></center></td> </tr> </thead> <tbody> <?php foreach($calendar as $days) :?> <tr> <?php for ($i=1;$i<=7;$i++) :?> <td> <?php echo isset($days[$i]) ? $days[$i] : ''; ?> </td> <?php endfor; ?> </tr> <?php endforeach ?> </tbody> </table> </body> </html>
|
|
|
96
|
Programación / Bases de Datos / Hola, me podrían ayudar?
|
en: 25 Febrero 2017, 19:59 pm
|
Hola estoy haciendo un calendario php mysql, ayudandome de un video. https://www.youtube.com/watch?feature=player_embedded&v=T0y32_nEbyshay un paso en que tienes que hacer "el contenido del calendario" los días en números. Lo hice bien pero cuando lo subo a mi servidor el resultado no es el mismo. la imagen esta en el enlace https://drive.google.com/file/d/0B6mh5xJztGS9bHZrd0tJNDA5cTg/view?usp=sharing<style> table.calendar{ border: solid; border-color: #B45F04; background-color: #F7D358; font-family: segoe script; } </style> <html lang="es"> <head>
</head> <body> <?php if (isset($_GET['day'])) { $day = $_GET['day']; }else{ $day = date("j"); }
if (isset($_GET['month'])) { $month = $_GET['month']; }else{ $month = date("n"); }
if (isset($_GET['year'])) { $year = $_GET['year']; }else{ $year = date("Y"); } //calender variable $currentTimeStamp = strtotime("$year-$month-$day"); $monthName = date("F", $currentTimeStamp); $numDays = date("t", $currentTimeStamp); $counter = 0; ?> <table border="1" class="calendar"> <tr> <td><input width="50px" type="button" value="<" name="previousbutton" style="cursor: pointer;"></td> <td colspan="5"><center><b><?php echo $monthName ." de ".$year ?></b></center></td> <td><input width="50px" type="button" value=">" name="nextbutton" style="cursor: pointer;"></td> </tr> <tr> <td width="50px"><center><b>Lunes</b></center></td> <td width="50px"><center><b>Martes</b></center></td> <td width="50px"><center><b>Miércoles</b></center></td> <td width="50px"><center><b>Jueves</b></center></td> <td width="50px"><center><b>Viernes</b></center></td> <td width="50px"><center><b>Sábado</b></center></td> <td width="50px"><center><b>Domingo</b></center></td> </tr> <?php echo "<tr>";
for ($i = 1; $i < $numDays+1; $i++, $counter++) { $timeStamp = strtotime("$year-$month-$i"); if ($i == 1) { $firstDay = date("w", $timeStamp); for($j = 0; $j < $firstDay; $j++, $counter++) { //black space echo "<td> </td>"; } } if ($counter % 7 == 0) { echo "<tr></tr>"; echo "<td align='center'>".$i."</td>"; } } echo "</tr>"; ?> </table> </body> </html> No sé lo que está mal lo revisé todo dos veces y no sé donde está el fallo. Gracias.
|
|
|
97
|
Programación / PHP / Hola alguien me podria ayudar con un calendario php mysql? Gracias
|
en: 19 Febrero 2017, 23:12 pm
|
Hola estoy haciendo un calendario php mysql, ayudandome de un video. https://www.youtube.com/watch?feature=player_embedded&v=T0y32_nEbyshay un paso en que tienes que hacer "el contenido del calendario" los días en números. Lo hice bien pero cuando lo subo a mi servidor el resultado no es el mismo. la imagen esta en el enlace https://drive.google.com/file/d/0B6mh5xJztGS9bHZrd0tJNDA5cTg/view?usp=sharing<style> table.calendar{ border: solid; border-color: #B45F04; background-color: #F7D358; font-family: segoe script; } </style> <html lang="es"> <head>
</head> <body> <?php if (isset($_GET['day'])) { $day = $_GET['day']; }else{ $day = date("j"); }
if (isset($_GET['month'])) { $month = $_GET['month']; }else{ $month = date("n"); }
if (isset($_GET['year'])) { $year = $_GET['year']; }else{ $year = date("Y"); } //calender variable $currentTimeStamp = strtotime("$year-$month-$day"); $monthName = date("F", $currentTimeStamp); $numDays = date("t", $currentTimeStamp); $counter = 0; ?> <table border="1" class="calendar"> <tr> <td><input width="50px" type="button" value="<" name="previousbutton" style="cursor: pointer;"></td> <td colspan="5"><center><b><?php echo $monthName ." de ".$year ?></b></center></td> <td><input width="50px" type="button" value=">" name="nextbutton" style="cursor: pointer;"></td> </tr> <tr> <td width="50px"><center><b>Lunes</b></center></td> <td width="50px"><center><b>Martes</b></center></td> <td width="50px"><center><b>Miércoles</b></center></td> <td width="50px"><center><b>Jueves</b></center></td> <td width="50px"><center><b>Viernes</b></center></td> <td width="50px"><center><b>Sábado</b></center></td> <td width="50px"><center><b>Domingo</b></center></td> </tr> <?php echo "<tr>";
for ($i = 1; $i < $numDays+1; $i++, $counter++) { $timeStamp = strtotime("$year-$month-$i"); if ($i == 1) { $firstDay = date("w", $timeStamp); for($j = 0; $j < $firstDay; $j++, $counter++) { //black space echo "<td> </td>"; } } if ($counter % 7 == 0) { echo "<tr></tr>"; echo "<td align='center'>".$i."</td>"; } } echo "</tr>"; ?> </table> </body> </html> No sé lo que está mal lo revisé todo dos veces y no sé donde está el fallo. Gracias.
|
|
|
99
|
Programación / PHP / MySQL ha devuelto un conjunto de valores vacío (es decir: cero columnas)...
|
en: 30 Diciembre 2016, 15:08 pm
|
Hola hice este formulario: Código : <!DOCTYPE html> <?php include('conectar.php'); ?> <head> <title>Materia</title> </head> <body> <center><font color="#333333" face="Segoe script" size="+6">Insertar deberes</font></center> <br> <br> <center> <form action="insertar1.php" method="post" name="form"> <font size="+1" color="#333333" face="Segoe script">Data:</font> <input type="date" name="ardata" id="ardata" style="background-color: lightblue; color: gray; border: inset; border-color: orange" required> <br> <font size="+1" face="Segoe script">Materia:</font> <input type="text" name="armateria" id="armateria" style="background-color: lightblue; color: gray; border: inset; border-color: orange" required placeholder="Pon la materia" max> <br> <font size="+1" face="Segoe script">Tarea:</font> <br> <textarea cols="50" rows="10" name="artarea" id="artarea" style="background-color: lightblue; color: gray; border: inset; border-color: orange" required placeholder="Pon tu/s tareas"></textarea> <br> <br> <input type="submit" value="Guardar datos" style="background-color: orange; border: inset; border-color: orange; cursor: pointer;"> <input type="reset" value="Limpiar formulario" style="background-color: orange; border: inset; border-color: orange; cursor: pointer;" name="ok"> </a> </form> </center> </body> </html>
Que esta conectado a la base de datos. Al hacer click te lleva al archivo insertar1.php Código : <?php //Recibir los datos y almacenarlos en variables include 'conectar.php'; $data = $_POST["ardata"]; $materia = $_POST["armateria"]; $tarea = $_POST["artarea"]; //consulta para insertar $insertar = "INSERT INTO 1esoa(Data, Materia, Tarea)VALUES('$data','$materia','$tarea')"; $verificar_usuario = mysql_query($conexion, "SELECT * FROM 1esoa WHERE Data = '$data'"); echo 'La data ya esta puesta'; } //Ejecutar consulta if(!resultado){ echo 'Error al insertar los datos'; echo '<a href="form3.php">Volver</a>'; }else{ echo 'Los datos se han insertado correctamente'; echo '<a href="form3.php">Volver</a>'; } //Cerrar conexion ?>
Me dice: Conectado Los datos se han insertado correctamente, pero voy a PHPmyAdmin para confirmarlo y me pone: MySQL ha devuelto un conjunto de valores vacío (es decir: cero columnas). ( La consulta tardó 0.0003 seg )
No se que es y como lo puedo solucionar. Gracias.
|
|
|
100
|
Programación / PHP / No me inserta los datos a la base de datos.
|
en: 19 Diciembre 2016, 17:17 pm
|
Hola hice este codigo: <!DOCTYPE html> <?php $servername = "sql201.260mb.net"; $username = "censurado"; $password = "censurado"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Conecxion fallida: " . $conn->connect_error); } echo "Conectado"; //Insert data if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['materia']) && !empty($_POST['materia']) && isset($_POST['tarea']) && !empty($_POST['tarea'])) { mysql_query("INSERT INTO 1eso_A (data,materia,tarea) VALUES ('$_POST[data]','$_POST[materia]','$_POST[tarea]')",$formulario); echo "datos insertados correctamente"; }else{ echo "problema al insertar los datos"; } ?> <script type="text/javascript"> function mensaje(){ alert("solo acepta números, puedes escribir hasta 10 caracteres"); } </script> <script type="text/javascript"> function solonumeros(e){ key=e.keyCode || e.which; teclado=String.fromCharCode(key); numeros="0123456789"; especiales="8-37-38-46-92-32-47";//array caracteres_especiales="160-47-46-59-58"; teclado_especial=false; for(var i in especiales){ if(key==especiales[i]){ teclado_especial=true; } } if(numeros.indexOf(teclado)==-1 && !teclado_especial){ return false; } } </script> <head> <title>Materia</title> </head> <body> <center><font color="#333333" face="Segoe script" size="+6">Insertar deberes</font></center> <br> <br> <center> <form action="procesar.php" method="post" name="form"> <font size="+1" color="#333333" face="Segoe script">Data:</font> <input type="text" name="data" onKeyPress="return solonumeros(event)" onpaste="return false" maxlength="10" style="background-color: lightblue; color: gray; border: inset; border-color: orange" value="-/-/-" id="data">  <input type="button" onclick="mensaje()" style=" cursor:help; background-color:lightgreen; border-bottom-color:#66FF00;" value="i"> <br> <br> <font size="+1" face="Segoe script">Materia:</font> <input type="text" name="materia" style="background-color: lightblue; color: gray; border: inset; border-color: orange" id="materia"> <br> <br> <font size="+1" face="Segoe script">Tarea:</font> <br> <br> <textarea cols="50" rows="10" name="tarea" style="background-color: lightblue; color: gray; border: inset; border-color: orange" id="tarea"></textarea> <br> <br> <a href="conectar.php"> <input type="submit" value="Enviar" onclick="guardardatos()" style="background-color: orange; border: inset; border-color: orange; cursor: pointer;"> <input type="reset" value="Limpiar formulario" style="background-color: orange; border: inset; border-color: orange; cursor: pointer;" name="ok" id="ok"> </a> </form> </center> </body> </html>
Este código esta conectado es decir que la conexión me va bien pero quiero que al insertar los datos en el formulario envie los datos en mi base de datos que esta conectado puse este código: //Insert data if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['materia']) && !empty($_POST['materia']) && isset($_POST['tarea']) && !empty($_POST['tarea'])) { mysql_query("INSERT INTO 1eso_A (data,materia,tarea) VALUES ('$_POST[data]','$_POST[materia]','$_POST[tarea]')",$formulario); echo "datos insertados correctamente"; }else{ echo "problema al insertar los datos"; }
No se si esta bien Lo puse y al guardarlo y subirlo en 260mb.net y lo visualuzo me pone conectado que esta bien pero despues me pone "problema al insertar los datos" cuyo frase puse yo al programar el c�digo eso creo que significa que el c�digo: //Insert data if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['materia']) && !empty($_POST['materia']) && isset($_POST['tarea']) && !empty($_POST['tarea'])) { mysql_query("INSERT INTO 1eso_A (data,materia,tarea) VALUES ('$_POST[data]','$_POST[materia]','$_POST[tarea]')",$formulario); echo "datos insertados correctamente"; }
hay algo mal y no se que es. Gracias
|
|
|
|
|
|
|