Está en la página 1de 6

pa hacer lo mismo de la clase 4 pero con CLASE(esto es pa mostrar las tablas de nuestro mysql): <?

php /** * @author * @copyright 2012 */ class conexion { var $servidor="localhost"; var $usuario="root"; var $clave=""; var $baseDatos="based"; var $conex; function __construct() { $this->conex=mysql_connect($this->servidor,$this->usuario,$this->clave) or die ("error de conexion"); mysql_select_db($this->baseDatos, $this->conex) or die ("error en base") ; if(isset($this->conex)) echo "exito"; else echo "error"; } function mostrar($tabla, $fila=0) { if (isset($this->conex)) { $sql="SELECT * FROM $tabla"; $res=mysql_query($sql, $this->conex); if(mysql_num_rows($res)>0) { $f=$fila+2; echo "<a href='conexion.php?fila=$f'>siguiente</a>"; echo "<table border='1'>"; echo "<tr>"; for($i=0; $i<mysql_num_fields($res); $i++) echo "<th>".mysql_field_name($res,$i)."</th>"; echo "</tr>"; $max=$fila+2>mysql_num_rows($res)?mysql_num_rows($res):$fila+2; for($i=$fila; $i<$max; $i++) { echo "<tr>"; for($j=0;$j<mysql_num_fields($res); $j++) { echo "<td>"; echo mysql_result($res,$i,$j); echo "</td>"; } echo "</tr>"; } echo "</table>"; }

else echo "no existe registros"; } else echo "no existe"; } } $a=new conexion(); $a->mostrar("usuario", $_REQUEST["fila"]); ?> --------------------------------------------------------------------------------------pa mostrar la tabla de mysql con paginacion(anterior - siguiente) lo de la tarea , para parar cuando ya no exista mas datos. <?php /** * @author * @copyright 2012 */ class conexion { var $servidor="localhost"; var $usuario="root"; var $clave=""; var $baseDatos="based"; var $conex; var $result; var $sql; var $filas; var $columnas; function __construct() { $this->conex=mysql_connect($this->servidor,$this->usuario,$this->clave) or die ("error de conexion"); mysql_select_db($this->baseDatos, $this->conex) or die ("error en base") ; if(isset($this->conex)) echo "exito"; else echo "error"; } function mostrar($tabla, $fila=0) { if (isset($this->conex)) { $this->sql="SELECT * FROM $tabla"; $this->result=mysql_query($this->sql, $this->conex); if(mysql_num_rows($this->result)>0) { $reg=1; $this->filas=mysql_num_rows($this->result); $this->columnas=mysql_num_fields($this->result); $f=$fila+$reg; $fa=$fila-$reg; if($fila>=$reg) echo "<a href='conexion.php?fila=$fa'>anterior</a>";

if($f<=$this->filas) echo "<a href='conexion.php?fila=$f'>siguiente</a>"; echo "<table border='1'>"; echo "<tr>"; for($i=0; $i<mysql_num_fields($this->result); $i++) echo "<th>".mysql_field_name($this->result,$i)."</th>"; echo "</tr>"; $max=$fila+$reg>mysql_num_rows($this->result)?mysql_num_rows($this->resul t):$fila+$reg; for($i=$fila; $i<$max; $i++) { echo "<tr>"; for($j=0;$j<mysql_num_fields($this->result); $j++) { echo "<td>"; echo mysql_result($this->result,$i,$j); echo "</td>"; } echo "</tr>"; } echo "</table>"; } else echo "no existe registros"; } else echo "no existe"; } } $a=new conexion(); $a->mostrar("usuario", $_REQUEST["fila"]); ?> ----------------------------------------------------------------------------------------pa hacer lo mismo de arriba pero esta ves en ves de siguiente y anterior hacemos por numeros osea pag1, pag2, etc <?php /** * @author * @copyright 2012 */ class conexion { var $servidor="localhost"; var $usuario="root"; var $clave=""; var $baseDatos="based"; var $conex; var $result; var $sql; var $filas; var $columnas; function __construct() {

$this->conex=mysql_connect($this->servidor,$this->usuario,$this->clave) or die ("error de conexion"); mysql_select_db($this->baseDatos, $this->conex) or die ("error en base") ; if(isset($this->conex)) echo "exito"; else echo "error"; } function mostrar($tabla, $fila=0) { if (isset($this->conex)) { $this->sql="SELECT * FROM $tabla"; $this->result=mysql_query($this->sql, $this->conex); if(mysql_num_rows($this->result)>0) { $reg=1; $this->filas=mysql_num_rows($this->result); $this->columnas=mysql_num_fields($this->result); $f=$fila+$reg; $fa=$fila-$reg; if($fila>=$reg) echo "<a href='conexion.php?fila=$fa'>anterior</a>"; if($this->filas>$reg) { $num=ceil($this->filas/$reg); for($i=1; $i<=$num; $i++ ) { $c=($i-1)*$reg; echo "<a href='conexion.php?fila=$c'>$i</a>"; } } if($f<=$this->filas) echo "<a href='conexion.php?fila=$f'>siguiente</a>"; echo "<table border='1'>"; echo "<tr>"; for($i=0; $i<mysql_num_fields($this->result); $i++) echo "<th>".mysql_field_name($this->result,$i)."</th>"; echo "</tr>"; $max=$fila+$reg>mysql_num_rows($this->result)?mysql_num_rows($this->resul t):$fila+$reg; for($i=$fila; $i<$max; $i++) { echo "<tr>"; for($j=0;$j<mysql_num_fields($this->result); $j++) { echo "<td>"; echo mysql_result($this->result,$i,$j); echo "</td>"; } echo "</tr>"; } echo "</table>"; } else echo "no existe registros"; } else

echo "no existe"; } } $a=new conexion(); $a->mostrar("usuario", $_REQUEST["fila"]); ?> --------------------------------------------------------------lo mismo de arriba pero aumentandolo pa insertar datos pero NO desd teclado <?php /** * @author * @copyright 2012 */ class conexion { var $servidor="localhost"; var $usuario="root"; var $clave=""; var $baseDatos="based"; var $conex; var $result; var $sql; var $filas; var $columnas; function __construct() { $this->conex=mysql_connect($this->servidor,$this->usuario,$this->clave) or die ("error de conexion"); mysql_select_db($this->baseDatos, $this->conex) or die ("error en base") ; if(isset($this->conex)) echo "exito"; else echo "error"; } function mostrar($tabla, $fila=0) { if (isset($this->conex)) { $this->sql="SELECT * FROM $tabla"; $this->result=mysql_query($this->sql, $this->conex); if(mysql_num_rows($this->result)>0) { $reg=1; $this->filas=mysql_num_rows($this->result); $this->columnas=mysql_num_fields($this->result); $f=$fila+$reg; $fa=$fila-$reg; if($fila>=$reg) echo "<a href='conexion.php?fila=$fa'>anterior</a>"; if($this->filas>$reg) { $num=ceil($this->filas/$reg); for($i=1; $i<=$num; $i++ )

{ $c=($i-1)*$reg; echo "<a href='conexion.php?fila=$c'>$i</a>"; } } if($f<=$this->filas) echo "<a href='conexion.php?fila=$f'>siguiente</a>"; echo "<table border='1'>"; echo "<tr>"; for($i=0; $i<mysql_num_fields($this->result); $i++) echo "<th>".mysql_field_name($this->result,$i)."</th>"; echo "</tr>"; $max=$fila+$reg>mysql_num_rows($this->result)?mysql_num_rows($this->resul t):$fila+$reg; for($i=$fila; $i<$max; $i++) { echo "<tr>"; for($j=0;$j<mysql_num_fields($this->result); $j++) { echo "<td>"; echo mysql_result($this->result,$i,$j); echo "</td>"; } echo "</tr>"; } echo "</table>"; } else echo "no existe registros"; } else echo "no existe"; } function insertar() { $this->filas=mysql_query($this->sql, $this->conex); if($this->filas>0) echo "insertado!!!"; else echo "no insertado"; } } $a=new conexion(); $a->sql="INSERT INTO usuario VALUES(23,'lionel','messi','m10','argentina',1)"; $a->mostrar("usuario", $_REQUEST["fila"]); ?>

También podría gustarte