Ver Mensaje Individual
  #8 (permalink)  
Antiguo 17/09/2012, 09:57
Avatar de Jorge1801
Jorge1801
 
Fecha de Ingreso: julio-2011
Ubicación: Colombia
Mensajes: 54
Antigüedad: 12 años, 10 meses
Puntos: 2
Respuesta: Extraer registros con PHP

Cita:
Iniciado por ananda Ver Mensaje
Extrae con mysql_fetch_array si los datos estan en mysql y lo otro, llevarlos a otra pagina, es mas facil extraerlos en esa pagina...

Yo estoy utilizando DOMdocument. Para poder extraer los datos de una tabla.

Tengo un archivo index.php que tiene lo siguiente:

<?php
$url="tablaejemplo.php";
$html=file_get_contents($url);

$dom = new DOMDocument();


$dom->loadHTML($html);


$dom->preserveWhiteSpace = false;

$tables = $dom->getElementsByTagName('tbody');


$rows = $tables->item(0)->getElementsByTagName('tr');


echo ' <table id="datatable" class="display">

<thead>
<tr>
<th>ID</th>
<th>Cedula</th>
<th>Nombre</th>

</tr>
</thead>
<tbody> ';
foreach ($rows as $row)
{

$cols = $row->getElementsByTagName('td');


echo "<tr>";
echo "<td>". $cols->item(0)->nodeValue. "</td>";
echo "<td>". $cols->item(1)->nodeValue. "</td>";
echo "<td>". $cols->item(2)->nodeValue. "</td>";

echo "</tr>";


}
echo '

</tbody>

</table>


';

?>


Y tengo otro archivo llamado tablaejemplo.php que tiene lo siguiente:


<table border="1">
<thead>
<tr>
<th>ID</th>
<th>Cedula</th>
<th>Nombre</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo "1" ?></td>
<td><?php echo "123" ?></td>
<td><?php echo "JORGE" ?></td>
</tr>
<tr>
<td>1</td>
<td>123</td>
<td>ANDRES</td>
</tr>
<tbody>
</table>


Pero al ejecutar el archivo index.php en el navegador, solo me sale la cabecera y la segunda fila. No se por que no me sale la primera fila.