{"id":375,"date":"2016-02-06T12:05:16","date_gmt":"2016-02-06T10:05:16","guid":{"rendered":"http:\/\/luismaseda.com\/wp\/?p=375"},"modified":"2016-02-09T13:37:52","modified_gmt":"2016-02-09T11:37:52","slug":"inicio-de-webrepertorio4-con-codeigniter","status":"publish","type":"post","link":"https:\/\/luismaseda.com\/wp\/?p=375","title":{"rendered":"Inicio de webRepertorio4 con CodeIgniter"},"content":{"rendered":"<p><span style=\"color: #993366;\"><strong><span style=\"font-size: 14pt;\">Funcionamiento<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">El controlador (<strong>inicio.php<\/strong>) hace las llamadas necesarias al modelo (<strong>torneos_model<\/strong>) para recopilar los datos necesarios para lanzar la vista (<strong>inicio.php<\/strong>).<\/span><\/p>\n<p><strong>La vista<\/strong> necesita los siguientes datos para mostrar la p\u00e1gina de inicio:<\/p>\n<ul>\n<li>la fecha del d\u00eda (<strong>fecha_hoy<\/strong>)<\/li>\n<li>el n\u00famero de registros de la tabla torneos (<strong>num_tor<\/strong>)<\/li>\n<li>el n\u00famero de registros de la tabla partidas (<strong>num_par<\/strong>)<\/li>\n<li>una tabla con los a\u00f1os en los que ha habido torneos, para cargar el men\u00fa lateral s\u00f3lo con esos a\u00f1os (<strong>tor_exi<\/strong>).<\/li>\n<\/ul>\n<p><strong>El controlador<\/strong> pide los datos que necesita la vista al modelo<\/p>\n<ul>\n<li><strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #993300;\">$numeroTorneos<\/span> = $this-&gt;Torneos_model-&gt;dame_numero_torneos();<\/span><\/strong><\/li>\n<li><strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #993300;\">$numeroPartidas<\/span> = $this-&gt;Torneos_model-&gt;dame_numero_partidas();<\/span><\/strong><\/li>\n<li><strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #993300;\">$torneosFinal<\/span> = $this-&gt;Torneos_model-&gt;dame_torneos_existen();<\/span><\/strong><\/li>\n<\/ul>\n<p>y se los env\u00eda a la vista en un array de datos<\/p>\n<ul>\n<li><span style=\"color: #993300;\"><strong><span style=\"font-family: courier new,courier,monospace;\">$datos = array(&#8216;fecha_hoy&#8217; =&gt; $fecha_hoy, &#8216;num_tor&#8217; =&gt; $numeroTorneos, &#8216;num_par&#8217; =&gt; $numeroPartidas, &#8216;tor_exi&#8217; =&gt; $torneosFinal);<\/span><\/strong><\/span><\/li>\n<\/ul>\n<p><strong>El modelo<\/strong> realiza los c\u00e1lculos necesarios mediante funciones para davolver los datos que le pide el controlador.<\/p>\n<ul>\n<li><strong><span style=\"color: #993300;\"><span style=\"font-family: courier new,courier,monospace;\">function dame_numero_torneos()<\/span><\/span><\/strong><\/li>\n<li><span style=\"color: #993300;\"><strong><span style=\"font-family: courier new,courier,monospace;\">function dame_numero_partidas()<\/span><\/strong><\/span><\/li>\n<li><span style=\"color: #993300;\"><strong><span style=\"font-family: courier new,courier,monospace;\">function dame_torneos_existen()<\/span><\/strong><\/span><\/li>\n<\/ul>\n<h2><span style=\"font-family: courier new,courier,monospace; color: #993366; font-size: 14pt;\">Los documentos de Inicio de webRepertorio4<\/span><\/h2>\n<p><span style=\"font-family: courier new,courier,monospace;\"><div class=\"su-accordion su-u-trim\"><\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\"><div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Controlador: inicio.php<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"><\/span><br \/>\n<span style=\"font-size: 12pt;\"><strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #000080;\"> function index()<\/span>{<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> \/\/cargo el helper de url, con funciones para trabajo con URL del sitio<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> $this-&gt;load-&gt;helper(&#8216;url&#8217;);<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/cargo el helper de date, con funciones para trabajo con fechas del sitio<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> $this-&gt;load-&gt;helper(&#8216;date&#8217;);<\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> $fecha_ahora = now();<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/preparando el dato de fecha de referencia para la p\u00e1gina de inicio<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> $format = &#8216;DATE_W3C&#8217;;<\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> $fecha = standard_date($format, $fecha_ahora);<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/ponemos en $fecha_hoy la fecha en formato dd-mm-AAAA<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #993300;\"> $fecha_hoy<\/span> = substr($fecha, 8, 2) . &#8216;-&#8216; . substr($fecha, 5, 2) . &#8216;-&#8216; . substr($fecha, 0, 4);<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/ponemos en $fecha_tor la fecha en formato AAAA-mm-dd<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> $fecha_tor = substr($fecha, 0, 4) . &#8216;-&#8216; . substr($fecha, 5, 2) . &#8216;-&#8216; . substr($fecha, 8, 2);<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/$fecha_partidas = date(&#8216;Y-m-d&#8217;,strtotime(&#8216;+7 days&#8217;, strtotime($fecha)));<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> $fecha_inipartidas = date(&#8216;Y-m-d&#8217;,strtotime(&#8216;+7 days&#8217;, strtotime($fecha)));<\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> $fecha_finpartidas = date(&#8216;Y-m-d&#8217;,strtotime(&#8216;-7 days&#8217;, strtotime($fecha)));<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/cargo el modelo de torneos<\/span><br \/>\n<span style=\"color: #993300;\"><strong><span style=\"font-family: courier new,courier,monospace;\"> $this-&gt;load-&gt;model(&#8216;Torneos_model&#8217;);<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/preparando el c\u00e1lculo del n\u00famero de torneos en la base de datos mispartidas<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #993300;\"> $numeroTorneos<\/span> = $this-&gt;Torneos_model-&gt;dame_numero_torneos();<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/preparando el c\u00e1lculo del n\u00famero de partidas en la base de datos mispartidas<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #993300;\"> $numeroPartidas<\/span> = $this-&gt;Torneos_model-&gt;dame_numero_partidas();<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/preparar una tabla con s\u00f3lo los a\u00f1os en los que existen torneos<\/span><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #993300;\">$torneosFinal<\/span> = $this-&gt;Torneos_model-&gt;dame_torneos_existen();<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/recopilo en un array los datos de env\u00edo a la vista<\/span><br \/>\n<span style=\"color: #993300;\"><strong><span style=\"font-family: courier new,courier,monospace;\"> $datos = array(&#8216;fecha_hoy&#8217; =&gt; $fecha_hoy, &#8216;num_tor&#8217; =&gt; $numeroTorneos, &#8216;num_par&#8217; =&gt; $numeroPartidas, &#8216;tor_exi&#8217; =&gt; $torneosFinal);<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/cargo la vista pasando el array con los datos recopilados<\/span><br \/>\n<span style=\"color: #000080; font-size: 12pt;\"><strong><span style=\"font-family: courier new,courier,monospace;\"> $this-&gt;load-&gt;view(&#8216;inicio&#8217;, $datos);<\/span><\/strong><\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\"><\/div><\/div><\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\"><div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Modelo: torneos_model.php<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"><\/span><\/p>\n<p><span style=\"color: #000080; font-size: 10pt;\"><strong><span style=\"font-family: courier new,courier,monospace;\">class Torneos_model extends CI_Model {<\/span><\/strong><\/span><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">function __construct(){<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> parent::__construct();<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #993300;\"><span style=\"font-family: courier new,courier,monospace;\">function dame_numero_torneos(){<\/span><\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> $mysqli = new mysqli(&#8216;localhost&#8217;, &#8216;root&#8217;, \u00bb, &#8216;mispartidas&#8217;);<\/span><\/strong><br \/>\n<span style=\"font-family: andale mono,monospace;\"> \/\/Indicar a la conexi\u00f3n de mysqli que use la codificacion UTF8 \u00a1\u00a1\u00a1MUY IMPORTANTE!!!<\/span><br \/>\n<strong><span style=\"font-family: andale mono,monospace;\">mysqli_set_charset($mysqli,\u00bbutf8&#8243;);<\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">if ($mysqli-&gt;connect_errno) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> echo \u00abFall\u00f3 la conexi\u00f3n a MySQL: (\u00bb . $mysqli-&gt;connect_errno . \u00ab) \u00bb . $mysqli-&gt;connect_errno;<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/$resultado = $mysqli-&gt;query(\u00abSELECT mt_cdgo FROM torneos ORDER BY mt_cdgo ASC\u00bb);<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> $resultado = $mysqli-&gt;query(\u00abSELECT * FROM torneos\u00bb);<\/span><\/strong><br \/>\n<span style=\"color: #993300;\"><strong> <span style=\"font-family: courier new,courier,monospace;\"> return mysqli_num_rows($resultado);<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/ Cerrar la conexi\u00f3n.<\/span><br \/>\n<strong><span style=\"font-family: andale mono,monospace;\">mysqli_close($mysqli);<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">}<\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/p>\n<p><span style=\"color: #993300;\"><strong><span style=\"font-family: courier new,courier,monospace;\">function dame_numero_partidas(){<\/span><\/strong><\/span><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> $mysqli = new mysqli(&#8216;localhost&#8217;, &#8216;root&#8217;, \u00bb, &#8216;mispartidas&#8217;);<\/span><\/strong><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/Indicar a la conexi\u00f3n de mysqli que use la codificacion UTF8 \u00a1\u00a1\u00a1MUY IMPORTANTE!!!<\/span><br \/>\n<strong><span style=\"font-family: andale mono,monospace;\">mysqli_set_charset($mysqli,\u00bbutf8&#8243;);<\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">if ($mysqli-&gt;connect_errno) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> echo \u00abFall\u00f3 la conexi\u00f3n a MySQL: (\u00bb . $mysqli-&gt;connect_errno . \u00ab) \u00bb . $mysqli-&gt;connect_errno;<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">$resultado2 = $mysqli-&gt;query(\u00abSELECT * FROM partidas\u00bb);<\/span><\/strong><br \/>\n<span style=\"color: #993300;\"><strong> <span style=\"font-family: courier new,courier,monospace;\"> return mysqli_num_rows($resultado2);<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/ Cerrar la conexi\u00f3n.<\/span><br \/>\n<strong><span style=\"font-family: andale mono,monospace;\">mysqli_close($mysqli);<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">}<\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/p>\n<p><span style=\"color: #993300;\"><strong><span style=\"font-family: courier new,courier,monospace;\">function dame_torneos_anyo($id){<\/span><\/strong><\/span><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> \/\/ $id viene en formato aaaa<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> $mysqli = new mysqli(&#8216;localhost&#8217;, &#8216;root&#8217;, \u00bb, &#8216;mispartidas&#8217;);<\/span><\/strong><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/Indicar a la conexi\u00f3n de mysqli que use la codificacion UTF8 \u00a1\u00a1\u00a1MUY IMPORTANTE!!!<\/span><br \/>\n<strong><span style=\"font-family: andale mono,monospace;\">mysqli_set_charset($mysqli,\u00bbutf8&#8243;);<\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">if ($mysqli-&gt;connect_errno) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> echo \u00abFall\u00f3 la conexi\u00f3n a MySQL: (\u00bb . $mysqli-&gt;connect_errno . \u00ab) \u00bb . $mysqli-&gt;connect_errno;<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">$resultado3 = $mysqli-&gt;query(\u00abSELECT * FROM torneos WHERE mt_anyo = &#8216;$id&#8217; ORDER BY mt_cdgo ASC\u00bb);<\/span><\/strong><br \/>\n<span style=\"color: #993300;\"><strong> <span style=\"font-family: courier new,courier,monospace;\"> return $resultado3;<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/ Cerrar la conexi\u00f3n.<\/span><br \/>\n<strong><span style=\"font-family: andale mono,monospace;\">mysqli_close($mysqli);<\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">}<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/p>\n<p><span style=\"color: #993300;\"><strong><span style=\"font-family: courier new,courier,monospace;\">function dame_torneos_existen(){<\/span><\/strong><\/span><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> $mysqli = new mysqli(&#8216;localhost&#8217;, &#8216;root&#8217;, \u00bb, &#8216;mispartidas&#8217;);<\/span><\/strong><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/Indicar a la conexi\u00f3n de mysqli que use la codificacion UTF8 \u00a1\u00a1\u00a1MUY IMPORTANTE!!!<\/span><br \/>\n<strong><span style=\"font-family: andale mono,monospace;\">mysqli_set_charset($mysqli,\u00bbutf8&#8243;);<\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">if ($mysqli-&gt;connect_errno) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> echo \u00abFall\u00f3 la conexi\u00f3n a MySQL: (\u00bb . $mysqli-&gt;connect_errno . \u00ab) \u00bb . $mysqli-&gt;connect_errno;<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/ Se seleccionan de la base los torneos comprendidos entre 1987 y 2017<\/span><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">$resultado3 = $mysqli-&gt;query(\u00abSELECT * FROM torneos WHERE ((mt_anyo &gt; 1987) AND (mt_anyo &lt; 2017))\u00bb);<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/ Se crea una tabla de 69 elementos conteniendo cada elemento un a\u00f1o desde 1988 hasta 2056<\/span><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">for ($i = 1; $i &lt;= 69; $i++) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> $anyo[$i]=$i + 1987;<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/ inicializar tabla de a\u00f1os ($anyoexiste) que tienen torneos con valor cero<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> for ($i = 1; $i &lt;= 69; $i++) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> $anyoexiste[$i]=0;<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/ contabilizamos el n\u00famero de torneos existentes en cada a\u00f1o en la tabla $anyoexiste<\/span><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">$conta_mad = 0;<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> while ($fila = mysqli_fetch_array($resultado3)) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> $conta_mad += 1;<\/span><\/strong><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> \/\/echo \u00abTorneo \u00bb . $conta_mad . \u00ab: \u00bb . $fila[&#8216;mt_torneo&#8217;] . \u00ab<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> \u00ab;<\/span><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">for ($i = 1; $i &lt;= 69; $i++) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> if ($anyo[$i] == $fila[&#8216;mt_anyo&#8217;]) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> $anyoexiste[$i]++;<\/span><\/strong><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> \/\/echo \u00abpaso por este a\u00f1o\u00bb . $fila[&#8216;mt_anyo&#8217;] . \u00bb &#8211; \u00bb . $i . \u00bb &#8211; \u00bb . $anyoexiste[$i] . \u00ab<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> \u00ab;<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> break;<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">\/\/ creamos una tabla ($torneosfinal) con aquellos a\u00f1os que SI tienen torneos en la tabla $anyoexiste<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> $k = 0;<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> for ($i = 1; $i &lt;= 69; $i++) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> if ($anyoexiste[$i] |= 0) {<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> $k++;<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> $torneosfinal[$k] = $anyo[$i];<\/span><\/strong><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> \/\/echo $i . \u00bb &#8211; \u00bb . $anyo[$i] . \u00bb &#8211; \u00bb . $anyoexiste[$i] . \u00ab<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> \u00ab;<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><br \/>\n<strong> <span style=\"font-family: courier new,courier,monospace;\"> }<\/span><\/strong><br \/>\n<span style=\"color: #993300;\"><strong> <span style=\"font-family: courier new,courier,monospace;\"> return $torneosfinal;<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/ Cerrar la conexi\u00f3n.<\/span><br \/>\n<strong><span style=\"font-family: andale mono,monospace;\">mysqli_close($mysqli);<\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\">}<\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\"><\/div><\/div><\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\"><div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Vista: Inicio.php<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"><\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\">&lt;!DOCTYPE html&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;head&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;meta charset=\u00bbutf-8&#8243; \/&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;meta name=\u00bbviewport\u00bb content=\u00bbwidth=device-width, initial-scale=1.0&#8243; \/&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;title&gt;WebReperetorio4&lt;\/title&gt;<\/span><br \/>\n<span style=\"color: #000080; font-family: courier new,courier,monospace;\"> <strong>&lt;?php include &#8216;includes\/head0.inc&#8217; ?&gt;<\/strong><\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/head&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;body&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div id=\u00bbwrapper\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;!&#8211; NAV TOP\u00a0 &#8211;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> <strong><span style=\"color: #000080;\">&lt;?php include &#8216;includes\/menu_superior0.inc&#8217; ?&gt;<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;!&#8211; \/. NAV TOP\u00a0 &#8211;&gt;<\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">&lt;!&#8211; Inicio Nav Lateral\u00a0 &#8211;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> <strong><span style=\"color: #000080;\">&lt;?php include &#8216;includes\/menu_lateral0.inc&#8217; ?&gt;<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;!&#8211; Fin Nav Lateral\u00a0 &#8211;&gt;<\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">&lt;!&#8211; Inicio Page-wrapper &#8211;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div id=\u00bbpage-wrapper\u00bb &gt;<\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">&lt;!&#8211; Inicio Page Inner &#8211;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div id=\u00bbpage-inner\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div class=\u00bbrow\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div class=\u00bbcol-md-12&#8243;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;h2&gt;Mi historial de Ajedrez&lt;\/h2&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;h5&gt;Bienvenido a la p\u00e1gina del historial de mi ajedrez. &lt;\/h5&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;!&#8211; \/. ROW\u00a0 &#8211;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;hr \/&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div class=\u00bbrow\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div class=\u00bbcol-md-6 col-sm-6 col-xs-6&#8243;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div class=\u00bbpanel panel-back noti-box\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;span class=\u00bbicon-box bg-color-red set-icon\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;i class=\u00bbfa fa-envelope-o\u00bb&gt;&lt;\/i&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/span&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div class=\u00bbtext-box\u00bb &gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;p class=\u00bbmain-text\u00bb&gt;&lt;?php\u00a0 echo $num_tor . \u00bb Torneos\u00bb; ?&gt; &lt;\/p&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;p class=\u00bbtext-muted\u00bb&gt;Torneos&lt;\/p&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div class=\u00bbcol-md-6 col-sm-6 col-xs-6&#8243;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div class=\u00bbpanel panel-back noti-box\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;span class=\u00bbicon-box bg-color-green set-icon\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;i class=\u00bbfa fa-bars\u00bb&gt;&lt;\/i&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/span&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;div class=\u00bbtext-box\u00bb &gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;p class=\u00bbmain-text\u00bb&gt;&lt;?php\u00a0 echo $num_par . \u00bb Partidas\u00bb; ?&gt;&lt;\/p&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;p class=\u00bbtext-muted\u00bb&gt;Partidas&lt;\/p&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;!&#8211; \/. ROW\u00a0 &#8211;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;hr \/&gt;<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> <span style=\"color: #000080;\">&lt;?php<\/span><\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> <span style=\"color: #000080;\"> echo \u00abEstos son los resultados &lt;br \/&gt;\u00bb;<\/span><\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> <span style=\"color: #000080;\"> echo $fecha_hoy . \u00ab&lt;br \/&gt;\u00bb;<\/span><\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> <span style=\"color: #000080;\"> echo $num_tor . \u00bb torneos&lt;br \/&gt;\u00bb;<\/span><\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> <span style=\"color: #000080;\"> echo $num_par . \u00bb partidas&lt;br \/&gt;&lt;br \/&gt;\u00bb;<\/span><\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #000080;\">$k = count($tor_exi);<\/span><\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> <span style=\"color: #000080;\"> echo \u00abk = \u00bb . $k;<\/span><\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> <span style=\"color: #000080;\"> echo \u00ab&lt;br \/&gt;&lt;br \/&gt;\u00bb;<\/span><\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #000080;\">for ($i = 1; $i &lt;= $k; $i++) {<\/span><\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> <span style=\"color: #000080;\"> echo \u00abtor_exi(\u00bb . $i . \u00ab) &#8211; \u00bb . $tor_exi[$i] . \u00ab&lt;br \/&gt;\u00bb;<\/span><\/span><\/strong><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> <span style=\"color: #000080;\"> }<\/span><\/span><\/strong><\/p>\n<p><strong><span style=\"font-family: courier new,courier,monospace;\"><span style=\"color: #000080;\">?&gt;<\/span><\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">&lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;!&#8211; \/. PAGE INNER\u00a0 &#8211;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;!&#8211; \/. PAGE WRAPPER\u00a0 &#8211;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/div&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;!&#8211; \/. WRAPPER\u00a0 &#8211;&gt;<\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">&lt;!&#8211; SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME&#8211;&gt;<\/span><br \/>\n<strong><span style=\"font-family: courier new,courier,monospace;\"> <span style=\"color: #000080;\">&lt;?php include &#8216;includes\/scripts0.inc&#8217; ?&gt;<\/span><\/span><\/strong><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">&lt;\/body&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace;\"> &lt;\/html&gt;<\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\"> <\/div><\/div><\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\"><div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Vista: menu_lateral0.inc<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"><\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">&lt;nav class=\u00bbnavbar-default navbar-side\u00bb role=\u00bbnavigation\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> &lt;div class=\u00bbsidebar-collapse\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> &lt;ul class=\u00bbnav\u00bb id=\u00bbmain-menu\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> &lt;li class=\u00bbtext-center\u00bb&gt;<\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> &lt;img src=\u00bbassets\/img\/maseda_luis5_80.jpg\u00bb class=\u00bbuser-image img-responsive\u00bb\/&gt;<\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> &lt;\/li&gt;<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">&lt;li&gt;<\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\">&lt;?php<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> echo &#8216;&lt;a class=\u00bbactive-menu\u00bb\u00a0 href=\u00bb&#8216; . site_url(\u00bb) . &#8216;\u00bb&gt;&lt;i class=\u00bbfa fa-home fa-2x\u00bb&gt;&lt;\/i&gt; Inicio&lt;\/a&gt;&#8217;;<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> ?&gt;<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> &lt;\/li&gt;<\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> &lt;?php<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> $k = count($tor_exi);<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\"><strong><span style=\"color: #000080;\">for ($i = $k; $i &gt;= 1; $i&#8211;) {<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> \/\/for ($i = 1; $i &lt;= $k; $i++) {<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> if ($tor_exi[$i] |= 0) {<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> echo &#8216;&lt;li&gt;&#8217;;<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> echo &#8216;&lt;a href=\u00bb&#8216; . site_url(&#8216;\/torneosanyo\/muestraanyo\/&#8217; . $tor_exi[$i]) . &#8216;\u00bb&gt;&lt;i class=\u00bbfa fa-sitemap fa-2x\u00bb&gt;&lt;\/i&gt; &#8216; . $tor_exi[$i] . &#8216;&lt;span class=\u00bbfa arrow\u00bb&gt;&lt;\/span&gt;&lt;\/a&gt;&#8217;;<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> echo &#8216;&lt;li&gt;&#8217;;<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> }<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> }<\/span><\/strong><\/span><br \/>\n<span style=\"font-family: andale mono,monospace;\"> <strong><span style=\"color: #000080;\"> ?&gt;<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">&lt;\/ul&gt;<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">&lt;\/div&gt;<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">&lt;\/nav&gt;<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\"><\/div><\/div><\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\"><\/div><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Funcionamiento El controlador (inicio.php) hace las llamadas necesarias al modelo (torneos_model) para recopilar los datos necesarios para lanzar la vista (inicio.php). La vista necesita los siguientes datos para mostrar la p\u00e1gina de inicio: la fecha del d\u00eda (fecha_hoy) el n\u00famero &hellip; <a href=\"https:\/\/luismaseda.com\/wp\/?p=375\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41,3],"tags":[16,26,29,28,4,30],"class_list":["post-375","post","type-post","status-publish","format-standard","hentry","category-codeigniter","category-desarrollo-web","tag-base-de-datos","tag-codeigniter","tag-controlador","tag-modelo","tag-php-2","tag-vista"],"_links":{"self":[{"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=375"}],"version-history":[{"count":24,"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":420,"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/375\/revisions\/420"}],"wp:attachment":[{"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}