Return to Snippet

Revision: 51861
at October 19, 2011 23:09 by alberomo


Updated Code
<table id="tabla">
	<thead>
  	<tr>
    	<?php //Crea la cabecera de las tablas. Pone los nombres de los campos en las columnas del thead de la maquetación HTML.
				for($i=0;$i<mysql_num_fields($RecordSet);$i++){
					echo ("<th>".mysql_field_name($RecordSet,$i)."</th>");
				}
			?> 
    </tr>
  </thead>
  <tbody>
  	<?php
			if (mysql_num_rows($RecordSet)==0){  //Si la bbdd de no tiene campos, muestra un mensaje indicandolo.
				echo "<tr>";
				echo "<td colspan=\"".mysql_num_fields($RecordSet)."\">No hay ningún campo</td>";
				echo "</tr>";
			}
			else{				
				while($row=mysql_fetch_array($RecordSet,MYSQL_ASSOC)){ //Se asigna a la array $row los valores de la funcion mysql_fetch_array (asociativa) que recorre las registros de la tabla, del primero al ultimo. 
				echo "<tr>";   //Se abren filas
						for ($k=0; $k<mysql_num_fields($RecordSet);$k++){	 			
							echo "<td>".$row[mysql_field_name($RecordSet,$k)]."</td>"; //Se usa el nombre del campo como indice del array $row y se recorren todos los registros.
						}
				echo "</tr>";	//Se cierran filas	
				}
			}
		?>
  </tbody>
</table>

Revision: 51860
at October 6, 2011 08:05 by alberomo


Initial Code
<table id="tabla">
	<thead>
  	<tr>
    	<?php //Crea la cabecera de las tablas. Pone los nombres de los campos en las columnas del thead de la maquetación HTML.
				for($i=0;$i<mysql_num_fields($RecordSet);$i++){
					echo ("<th>".mysql_field_name($RecordSet,$i)."</th>");
				}
			?> 
    </tr>
  </thead>
  <tbody>
  	<?php
			if (mysql_num_rows($RecordSet)==0){  //Si la bbdd de no tiene campos, muestra un mensaje indicandolo.
				echo "<tr>";
				echo "<td colspan=\"".mysql_num_fields($RecordSet)."\">No hay ningún campo</td>";
				echo "</tr>";
			}
			else{				
				while($row=mysql_fetch_array($RecordSet,MYSQL_ASSOC)){ //Se asigna a la array $row los valores de la funcion mysql_fetch_array (asociativa) que recorre las registros de la tabla, del primero al ultimo. 
				echo "<tr>";   //Se abren filas
						for ($k=0; $k<mysql_num_fields($RecordSet);$k++){	 			
							echo "<td>".$row[mysql_field_name($RecordSet,$k)]."</td>"; //Se usa el nombre del campo como indice del array $row y se recorren todos los registros.
						}
				echo "</tr>";	//Se cierran filas	
				}
			}
		?>
  </tbody>
</table>

Initial URL


Initial Description
It uses a variable with a RecordSet. db_query PHP Functions can be used to have the REcordSet(http://snipplr.com/view/59419/php-connexion-to-mysql-ddbb-sql-query-and-creation-of-a-record-set/).

Then fill the tables with the data of the RecordSet.

Initial Title
Table populated dinamically without using ADODB php library code

Initial Tags
php

Initial Language
PHP