{"id":338,"date":"2016-02-03T09:27:44","date_gmt":"2016-02-03T07:27:44","guid":{"rendered":"http:\/\/luismaseda.com\/wp\/?p=338"},"modified":"2016-02-09T13:39:10","modified_gmt":"2016-02-09T11:39:10","slug":"tratando-con-mysqli","status":"publish","type":"post","link":"https:\/\/luismaseda.com\/wp\/?p=338","title":{"rendered":"Contando registros con mysqli (mysqli_num_rows)"},"content":{"rendered":"<p><span style=\"color: #993366; font-size: 12pt;\">Los documentos de Inicio de webRepertorio4<\/span><\/p>\n<div class=\"su-accordion su-u-trim\"><\/div>\n<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<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"><\/p>\n<p><strong><span style=\"font-family: andale mono,monospace; color: #993300;\">$this-&gt;load-&gt;model(&#8216;Torneos_model&#8217;);<\/span><\/strong><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/preparando el c\u00e1lculo del n\u00famero de torneos en la base de datos mispartidas<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\"><strong><span style=\"color: #993300;\">$numeroTorneos<\/span><\/strong> = $this-&gt;Torneos_model-&gt;dame_numero_torneos();<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/preparando el c\u00e1lculo del n\u00famero de partidas en la base de datos mispartidas<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\"><strong><span style=\"color: #993300;\">$numeroPartidas<\/span><\/strong> = $this-&gt;Torneos_model-&gt;dame_numero_partidas();<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/recopilo en un array los datos de env\u00edo a la vista<\/span><\/p>\n<p><span style=\"color: #993300;\"><strong><span style=\"font-family: andale mono,monospace;\">$datos = array(&#8216;fecha_hoy&#8217; =&gt; $fecha_hoy, &#8216;num_tor&#8217; =&gt; $numeroTorneos, &#8216;num_par&#8217; =&gt; $numeroPartidas);<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/cargo la vista pasando el array con los datos recopilados<\/span><\/p>\n<p><strong><span style=\"font-family: andale mono,monospace; color: #993300;\">$this-&gt;load-&gt;view(&#8216;inicio&#8217;, $datos);<\/span><\/strong><\/p>\n<p><\/div><\/div>\n<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<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"><\/p>\n<p><strong><span style=\"font-family: andale mono,monospace; color: #993300;\">function dame_numero_torneos(){<\/span><\/strong><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/ Conexi\u00f3n a la base de datos<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">$mysqli = new mysqli(&#8216;localhost&#8217;, &#8216;root&#8217;, \u00bb, &#8216;mispartidas&#8217;);<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">if ($mysqli-&gt;connect_errno) {<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">echo \u00abFall\u00f3 la conexi\u00f3n a MySQL: (\u00bb . $mysqli-&gt;connect_errno . \u00ab) \u00bb . $mysqli-&gt;connect_errno;<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">}<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/Consulta a la base de datos<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">$resultado = $mysqli-&gt;query(\u00abSELECT * FROM torneos\u00bb);<\/span><\/p>\n<p><strong><span style=\"font-family: andale mono,monospace; color: #993300;\">return mysqli_num_rows($resultado);<\/span><\/strong><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">}<\/span><\/p>\n<p><span style=\"color: #993300;\"><strong><span style=\"font-family: andale mono,monospace;\">function dame_numero_partidas(){<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/ Conexi\u00f3n a la base de datos<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">$mysqli = new mysqli(&#8216;localhost&#8217;, &#8216;root&#8217;, \u00bb, &#8216;mispartidas&#8217;);<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">if ($mysqli-&gt;connect_errno) {<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">echo \u00abFall\u00f3 la conexi\u00f3n a MySQL: (\u00bb . $mysqli-&gt;connect_errno . \u00ab) \u00bb . $mysqli-&gt;connect_errno;<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">}<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">\/\/Consulta a la base de datos<\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">$resultado2 = $mysqli-&gt;query(\u00abSELECT * FROM partidas\u00bb);<\/span><\/p>\n<p><span style=\"color: #993300;\"><strong><span style=\"font-family: andale mono,monospace;\">return mysqli_num_rows($resultado2);<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: andale mono,monospace;\">}<\/span><\/p>\n<p><\/div><\/div>\n<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<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"><\/p>\n<p><span style=\"color: #993300;\"><strong><span style=\"font-family: andale mono,monospace;\">echo \u00abEstos son los resultados &lt;\/br &gt;\u00bb;<\/span><\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong><span style=\"font-family: andale mono,monospace;\"> echo $fecha_hoy . \u00bb &lt;\/br &gt;\u00bb;<\/span><\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong><span style=\"font-family: andale mono,monospace;\"> echo $num_tor . \u00bb torneos&lt;\/br &gt;\u00bb;<\/span><\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong><span style=\"font-family: andale mono,monospace;\"> echo $num_par . \u00bb partidas&lt;\/br &gt;\u00bb;<\/span><\/strong><\/span><\/p>\n<p><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Los documentos de Inicio de webRepertorio4<\/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":[26,29,28,11,30],"class_list":["post-338","post","type-post","status-publish","format-standard","hentry","category-codeigniter","category-desarrollo-web","tag-codeigniter","tag-controlador","tag-modelo","tag-mysql","tag-vista"],"_links":{"self":[{"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/338","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=338"}],"version-history":[{"count":28,"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":417,"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions\/417"}],"wp:attachment":[{"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/luismaseda.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}