<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>reweb Labs &#187; MySQL</title>
	<atom:link href="http://labs.reweb.com.ar/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://labs.reweb.com.ar</link>
	<description>Donde la magia sucede</description>
	<lastBuildDate>Thu, 25 Feb 2010 11:37:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL result to KML file output &#8211; PHP</title>
		<link>http://labs.reweb.com.ar/37-mysql-result-to-kml-file-output-php</link>
		<comments>http://labs.reweb.com.ar/37-mysql-result-to-kml-file-output-php#comments</comments>
		<pubDate>Sun, 16 Aug 2009 17:42:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[KML]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=37</guid>
		<description><![CDATA[Description
This package offers a function called mysqlAKML (resource $mysqlResult, string $documentName=&#8217;kml&#8217;, string $itemName=&#8217;Placemark&#8217;); used to output a Mysql result with the following fields:
name: TEXTVALUE &#8211; The Name of the marker
description: TEXTVALUE &#8211; The description shown in the info window when marker clicked
coordinates: TEXTVALUE as (DOUBLE + &#8216;, &#8216; + DOUBLE) like &#8220;longitude, latitude&#8221;
Usage
So an easy [...]]]></description>
			<content:encoded><![CDATA[<h2>Description</h2>
<p>This package offers a function called <strong>mysqlAKML</strong> (resource $mysqlResult, string $documentName=&#8217;kml&#8217;, string $itemName=&#8217;Placemark&#8217;); used to output a Mysql result with the following fields:</p>
<p><em>name</em>: TEXTVALUE &#8211; The Name of the marker<br />
<em>description</em>: TEXTVALUE &#8211; The description shown in the info window when marker clicked<br />
<em>coordinates</em>: TEXTVALUE as (DOUBLE + &#8216;, &#8216; + DOUBLE) like &#8220;longitude, latitude&#8221;</p>
<h2>Usage</h2>
<p>So an easy way to obtain the KML would be:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$qString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT
markerName AS name,
myText AS description,
CONCAT (latitude, ', ', longitude) AS coordinates
FROM myTable&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$qString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$myKML</span> <span style="color: #339933;">=</span> mysql_KML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A complete example:</p>
<h3>File getPoints.php</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">require</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'connetion.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysqlAKML-1.1.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// obtain the MySQL resutl</span>
<span style="color: #000088;">$makers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// KML Content-Type (application/vnd.google-earth.kml+xml)</span>
<span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: application/vnd.google-earth.kml+xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=&quot;markers.kml&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Display the file content</span>
<span style="color: #b1b100;">echo</span> mysql_KML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$markers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Then, if we want to load this KML in a Google Map with the Google Maps API with JavaScript, we shoul add the following code to our load() function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// JavaScript</span>
<span style="color: #003366; font-weight: bold;">function</span> load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
...
...
<span style="color: #006600; font-style: italic;">// add Markers fetched from the DB to the map</span>
<span style="color: #003366; font-weight: bold;">var</span> geoXml <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> GGeoXml<span style="color: #009900;">&#40;</span>PATH_TO_FILE <span style="color: #339933;">+</span> <span style="color: #3366CC;">'getPoints.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
map.<span style="color: #660066;">addOverlay</span><span style="color: #009900;">&#40;</span>geoXml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Thats all! Feel free to modify the file but remember to leave my name! See the working example in the link below</p>
<h2>Working Example</h2>
<p><a href='http://www.cordobalquila.com.ar/inmobiliarias'>Example</a></p>
<h2>Downloads</h2>
<p><a href="http://labs.reweb.com.ar/wp-content/uploads/2009/08/mysqlakml-11.rar">Download Package File (mysqlAKML-1.1.php)</a></p>
<h2>Usefull Links</h2>
<p><a href='http://code.google.com/intl/es-AR/apis/maps/documentation/reference.html#GGeoXml'>GGeoXML in Google Maps API Reference</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/37-mysql-result-to-kml-file-output-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pasar resultado MySQL a archivo XML o E4X para AJAX</title>
		<link>http://labs.reweb.com.ar/20-pasar-resultado-mysql-a-archivo-xml-o-e4x-para-ajax</link>
		<comments>http://labs.reweb.com.ar/20-pasar-resultado-mysql-a-archivo-xml-o-e4x-para-ajax#comments</comments>
		<pubDate>Thu, 16 Jul 2009 14:13:13 +0000</pubDate>
		<dc:creator>joarobles</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[E4X]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=20</guid>
		<description><![CDATA[Gente, acá les acerco una función de mi autoría que convierte un resultado de consulta MySQL en un archivo XML, veamos un ejemplo:
Si tuvieramos la siguiente tabla usuarios:



id
nombre
email










1
Pablo
pablo@mail.com


2
Marcos
marcos@mail.com




Con la consulta SQL dada por:

SELECT * FROM usuarios;

Y queremos obtener el siguiente archivo XML:

&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62;
&#60;resultados&#62;
&#60;item&#62;
&#60;id&#62;1&#60;/id&#62;
&#60;nombre&#62;Pablo&#60;/nombre&#62;
&#60;mail&#62;pablo@mail.com&#60;/mail&#62;
&#60;/item&#62;
&#60;item&#62;
&#60;id&#62;2&#60;/id&#62;
&#60;nombre&#62;Marcos&#60;/nombre&#62;
&#60;mail&#62;marcos@mail.com&#60;/mail&#62;
&#60;/item&#62;

Simplemente debemos ejecutar la siguiente instrucción en PHP:

&#60;?
require &#40;'conexion.php'&#41;;
require &#40;'mysqlAXML-1.0.php'&#41;;
&#160;
header&#40;&#34;Content-type: text/xml&#34;&#41;;
&#160;
$consulta = [...]]]></description>
			<content:encoded><![CDATA[<p>Gente, acá les acerco una función de mi autoría que convierte un resultado de consulta MySQL en un archivo XML, veamos un ejemplo:</p>
<p>Si tuvieramos la siguiente tabla <em>usuarios</em>:</p>
<table border="0">
<tbody>
<tr>
<td>id</td>
<td>nombre</td>
<td>email</td>
</tr>
<tr>
<td>
<hr /></td>
<td>
<hr /></td>
<td>
<hr /></td>
</tr>
<tr>
<td>1</td>
<td>Pablo</td>
<td>pablo@mail.com</td>
</tr>
<tr>
<td>2</td>
<td>Marcos</td>
<td>marcos@mail.com</td>
</tr>
</tbody>
</table>
<p>
Con la consulta SQL dada por:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> usuarios;</pre></div></div>

<p>Y queremos obtener el siguiente archivo XML:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resultados<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nombre<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Pablo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nombre<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pablo@mail.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nombre<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Marcos<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nombre<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>marcos@mail.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Simplemente debemos ejecutar la siguiente instrucción en PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">require</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'conexion.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysqlAXML-1.0.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$consulta</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM usuarios&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$resultado</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error en '<span style="color: #006699; font-weight: bold;">$consulta</span>' &amp;lt;br /&amp;gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> mysql_XML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultado</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>O para obtener el resultado en formato E4X:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">echo</span> mysql_E4X<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultado</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>La sintaxis general es la siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
mysql_XML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultado</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span> <span style="color: #000088;">$nombreDoc</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'resultados'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nombreItem</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'item'</span> <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Pueden descargar el archivo ZIP con la libreria desde aquí: <a href="http://labs.reweb.com.ar/wp-content/uploads/2009/07/mysqlaxml-10.zip">mysqlaxml-1.0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/20-pasar-resultado-mysql-a-archivo-xml-o-e4x-para-ajax/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Paginar Vector de Resultados en PHP</title>
		<link>http://labs.reweb.com.ar/3-paginar-vector-de-resultados-en-php</link>
		<comments>http://labs.reweb.com.ar/3-paginar-vector-de-resultados-en-php#comments</comments>
		<pubDate>Wed, 13 May 2009 02:56:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=3</guid>
		<description><![CDATA[Hace un tiempo me surgió el problema de paginar un vector (Array) de resultados de una búsqueda, por lo que busqué la forma de crear una función que me permitiera listar los items correspondientes, pasandole por parámetros el vector en cuestión, el límite de resultados a mostrar y la página solicitada.
He aquí mi solución (es [...]]]></description>
			<content:encoded><![CDATA[<p>Hace un tiempo me surgió el problema de paginar un vector (Array) de resultados de una búsqueda, por lo que busqué la forma de crear una función que me permitiera listar los items correspondientes, pasandole por parámetros el vector en cuestión, el límite de resultados a mostrar y la página solicitada.</p>
<p>He aquí mi solución (es una base, que necesita ser pulida, eso les dejo a ustedes <img src="http://www.cristalab.com/foros/images/smiles/icon_wink.gif" border="0" alt=";)" /> )</p>
<p><strong>paginar.php</strong></p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php"><span class="php_fx__keyword">function</span> paginar(<span class="php_fx__keyword">$</span><span class="php_fx__variable">v</span>, <span class="php_fx__keyword">$</span><span class="php_fx__variable">l</span>, <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>) {</pre>
<p>Primero que nada definimos la función junto con las variables que se han de pasar como parámetro, ahora bien, necesitamos saber cuales son las condiciones de inicio de nuestro paginador, tales como la cantidad de páginas a mostrar, en función de la longitud del vector y del límite de items a desplegar:</p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php"><span class="php_fx__com">// DEFINIMOS LA CANTIDAD DE PÁGINAS</span> 
<span class="php_fx__keyword">$</span><span class="php_fx__variable">paginas</span> = <span class="php_fx__func">ceil</span>(<span class="php_fx__func">count</span>(<span class="php_fx__keyword">$</span><span class="php_fx__variable">v</span>) / <span class="php_fx__keyword">$</span><span class="php_fx__variable">l</span>);</pre>
<p>Ahora bien, si queremos mostrar cada item del vector $v necesitaremos recorrerlo con un bucle, pero&#8230; ¿desde dónde empezaríamos a mostrar y hasta dónde? Para ello necesitamos definir las condiciones de nuestro bucle recorredor como sigue:</p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php"><span class="php_fx__com">// CONDICION DE INICIO</span> 
<span class="php_fx__keyword">$</span><span class="php_fx__variable">inicio</span> = (<span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span><span class="php_fx__number">-1</span>)*<span class="php_fx__keyword">$</span><span class="php_fx__variable">l</span>; 

<span class="php_fx__com">// CONDICION DE FINAL</span> 
<span class="php_fx__keyword">$</span><span class="php_fx__variable">final</span> = <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>*<span class="php_fx__keyword">$</span><span class="php_fx__variable">l</span>;</pre>
<p>Y ya estamos listos para empezar a recorrer el vector mostrando cada resultado dentro de un div de id=&#8221;item&#8221; dentro del div de resultados. Debemos tener en cuenta que, si no existiera el item i-ésimo dentro del vector $v tenemos que dejar de listar items:</p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php"><span class="php_fx__com">// MOSTRAMOS LOS ITEMS RESPECTIVOS</span> 
      <span class="php_fx__keyword">echo</span> <span class="php_fx__string1">'&lt;div id="resultados"&gt;'</span>; 
      <span class="php_fx__keyword">for</span> (<span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>=<span class="php_fx__keyword">$</span><span class="php_fx__variable">inicio</span>; <span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>&lt;<span class="php_fx__keyword">$</span><span class="php_fx__variable">final</span>; <span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>++) { 
         <span class="php_fx__keyword">if</span> (<span class="php_fx__keyword">isset</span>(<span class="php_fx__keyword">$</span><span class="php_fx__variable">v</span>[<span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>])) 
            <span class="php_fx__keyword">echo</span> <span class="php_fx__string2">"&lt;div id=\"item\"&gt;$i.- $v[$i]&lt;/div&gt;"</span>; 
         <span class="php_fx__keyword">else</span>  
            <span class="php_fx__keyword">break</span>; 
      } 
      <span class="php_fx__keyword">echo</span> <span class="php_fx__string1">'&lt;/div&gt;'</span>;</pre>
<p>Listo, tenemos los resultados correspondientes a la página $p, pero necesitaríamos mostrar el total de páginas a modo de menú de hipervínculos para poder navegar entre los ítems. Para ello comprobaremos si nos encontramos en la primera pagina para no mostrar &#8220;Página anterior&#8221; o en la última para no mostrar &#8220;Página siguiente&#8221;, además de no crear un vínculo a la misma página:</p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php"><span class="php_fx__com">// LISTAMOS LAS PÁGINAS</span> 
      <span class="php_fx__keyword">echo</span> <span class="php_fx__string1">'&lt;div id="paginas"&gt;'</span>; 
      <span class="php_fx__keyword">if</span> (<span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>&gt;<span class="php_fx__number">1</span>) 
         <span class="php_fx__keyword">echo</span> <span class="php_fx__string2">"&lt;a href=\"index.php?p="</span> . (<span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span><span class="php_fx__number">-1</span>) . <span class="php_fx__string2">"\"&gt;P&amp;aacute;gina Anterior&lt;/a&gt;&amp;nbsp;-&amp;nbsp;"</span>; 

      <span class="php_fx__keyword">for</span> (<span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>=<span class="php_fx__number">1</span>; <span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>&lt;=<span class="php_fx__keyword">$</span><span class="php_fx__variable">paginas</span>; <span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>++) { 
         <span class="php_fx__keyword">if</span> (<span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span> == <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>) 
            <span class="php_fx__keyword">echo</span> <span class="php_fx__string2">"&lt;strong&gt;$i&lt;/strong&gt;&amp;nbsp;"</span>; 
         <span class="php_fx__keyword">else</span>  
            <span class="php_fx__keyword">echo</span> <span class="php_fx__string2">"&lt;a href=\"index.php?p=$i\"&gt;$i&lt;/a&gt;&amp;nbsp;"</span>; 
      } 

      <span class="php_fx__keyword">if</span> (<span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>&lt;<span class="php_fx__keyword">$</span><span class="php_fx__variable">paginas</span>) 
         <span class="php_fx__keyword">echo</span> <span class="php_fx__string2">"&amp;nbsp;-&amp;nbsp;&lt;a href=\"index.php?p="</span> . (<span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span><span class="php_fx__number">+1</span>) . <span class="php_fx__string2">"\"&gt;P&amp;aacute;gina Siguiente&amp;nbsp;&lt;/a&gt;"</span>; 
      <span class="php_fx__keyword">echo</span> <span class="php_fx__string1">'&lt;/div&gt;'</span>; 
<span class="php_fx__keyword">return</span>; 
   }</pre>
<p>Eso sería todo, para llamar a la función simplemente realizamos:</p>
<p><strong>index.php</strong></p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php">
<div class="php_code_block"><span class="php_fx__phpopentag">&lt;?php</span> 
   <span class="php_fx__keyword">$</span><span class="php_fx__variable">vector</span> = <span class="php_fx__keyword">array</span>(<span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span> ); 

   <span class="php_fx__keyword">require</span> (<span class="php_fx__string2">"paginar.php"</span>); 

   <span class="php_fx__keyword">if</span> (<span class="php_fx__keyword">isset</span>(<span class="php_fx__global">$_GET</span>[p])) 
      <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span> = <span class="php_fx__global">$_GET</span>[p]; 
   <span class="php_fx__keyword">else</span>  
      <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>=<span class="php_fx__number">1</span>; 

   paginar(<span class="php_fx__keyword">$</span><span class="php_fx__variable">vector</span>, <span class="php_fx__number">10</span>, <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>); 
<span class="php_fx__phpclosetag">?&gt;</span></div>
</pre>
<p>Espero que les sirva de base para un desarrollo más complejo, saludos!</p>
<p>Pueden ver el ejemplo funcionando en <a class="arti_link" href="http://www.reweb.com.ar/labs/paginarVector/">http://www.reweb.com.ar/labs/paginarVector/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/3-paginar-vector-de-resultados-en-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
