SI alquien me pudiese mostrar algun ejemplo funcional y/o utilizable en la realidad de herencias en PHP estaria muy agradecido.
Gracias.
Gracias.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menúsession_start();
session_register("carro");
echo $carro;
session_start();
$_SESSION['carro'] = "mi carrito";
echo $_SESSION['carro'];
function Cfecha($fec)
{
$cua = substr($fec,0,4);
if(ereg("/",$cua)){$fecha=substr($fec,6,4)."/".substr($fec,3,2)."/".substr($fec,0,2);}
else{$fecha=substr($fec,8,2)."/".substr($fec,5,2)."/".substr($fec,0,4);}
return $fecha;
}
<?
echo Cfecha("10/12/2009");
?>
<?
echo Cfecha("2009/12/01");
?>
CREATE TABLE `personal` (
`dni` VARCHAR( 8 ) NOT NULL ,
`nombres` VARCHAR( 30 ) NOT NULL ,
`apellidos` VARCHAR( 30 ) NOT NULL ,
`fecnac` DATE NOT NULL ,
PRIMARY KEY ( `dni` )
) ENGINE = MYISAM ;
INSERT INTO `personal` VALUES ('45784785', 'Juan Carlos', 'Guerrero Irigoin', '1985-08-08');
INSERT INTO `personal` VALUES ('45985521', 'Pedro Ricardo', 'Garcia Lopez', '1983-03-16');
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Documento sin título</title>
</head>
<body>
</body>
</html>
<?
function lista($que)
{
$con = mysql_connect('localhost','root','root');
mysql_select_db('web',$con);
$res = mysql_query($que);
echo "<table border='1'>";
while($row=mysql_fetch_array($res))
{
echo "<tr>";
for($i=0;$i<mysql_num_fields($res);$i++)
{
echo "<td>".$row[$i]."</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
Empieza el listado
<?
$sql = "select dni,nombres,apellidos,fecnac from personal";
lista($sql);
?>
<script>
function efecto(id,tip)
{
var col = "#3399FF";
if(tip==2){col="";}
var cel = document.getElementById(id);
cel.style.backgroundColor=col;
}
</script>
<?
function lista($que)
{
$con = mysql_connect('localhost','root','root');
mysql_select_db('web',$con);
$res = mysql_query($que);
echo "<table border='1'>";
while($row=mysql_fetch_array($res))
{
echo "<tr id='tr$row[0]' onmouseover=efecto('tr$row[0]',1); onmouseout=efecto('tr$row[0]',2); style='cursor:pointer'>";
for($i=0;$i<mysql_num_fields($res);$i++)
{
echo "<td>".$row[$i]."</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
Empieza el listado
<?
$sql = "select dni,nombres,apellidos,fecnac from personal";
lista($sql);
?>
<?
function lista($que,$ali,$wid)
{
$con = mysql_connect('localhost','root','root');
mysql_select_db('web',$con);
$res = mysql_query($que);
echo "<table border='1'>";
while($row=mysql_fetch_array($res))
{
echo "<tr id='tr$row[0]' onmouseover=efecto('tr$row[0]',1); onmouseout=efecto('tr$row[0]',2); style='cursor:pointer'>";
for($i=0;$i<mysql_num_fields($res);$i++)
{
echo "<td width='$wid[$i] px' align='$ali[$i]'>".$row[$i]."</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
Empieza el listado
<?
$sql = "select dni,nombres,apellidos,fecnac from personal";
lista($sql);
?>
<?
$sql = "select dni,nombres,apellidos,fecnac from personal"; //consulta
$ali = array("center","left","left","center"); //alineacion
$wid = array(50,350,200,150); //width
lista($sql,$ali,$wid);
?>
<script>
function efecto(id,tip)
{
var col = "#3399FF";
if(tip==2){col="";}
var cel = document.getElementById(id);
cel.style.backgroundColor=col;
}
function llama(php)
{
document.location.href=php;
}
</script>
<?
function lista($que,$ali,$wid,$ico)
{
$con = mysql_connect('localhost','root','root');
mysql_select_db('web',$con);
$res = mysql_query($que);
echo "<table border='1'>";
while($row=mysql_fetch_array($res))
{
echo "<tr id='tr$row[0]' onmouseover=efecto('tr$row[0]',1); onmouseout=efecto('tr$row[0]',2); style='cursor:pointer'>";
foreach($ico as $sel=>$val)
{
echo "<td align='center' width='20px' onclick=llama('".$val[2]."?id=".$row[0]."');><img src='img/".$val[0]."' title='".$val[1]."'></td>";
}
for($i=0;$i<mysql_num_fields($res);$i++)
{
echo "<td width='$wid[$i] px' align='$ali[$i]'>".$row[$i]."</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
Empieza el listado
<?
$sql = "select dni,nombres,apellidos,fecnac from personal"; //consulta
$ali = array("center","left","left","center"); //alineacion
$wid = array(50,350,200,150); //width
$ico = array(
array("angry.gif","Click para ver detalles","detalles.php"),
array("cheesy.gif","Click para modificar","modificar.php")
);
lista($sql,$ali,$wid,$ico);
?>
CREATE TABLE `personal` (
`idpersonal` varchar(8) NOT NULL,
`nombres` varchar(45) NOT NULL,
`apellidos` varchar(45) NOT NULL,
`clave` varchar(45) NOT NULL,
`fecnac` date NOT NULL,
`fecreg` date NOT NULL,
`imagen` text,
`sexo` char(1) default NULL,
`estado` char(1) default NULL,
PRIMARY KEY (`idpersonal`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `personal` VALUES ('41338110', 'Juar Carlos', 'Malca Pereda', 'clave1' ,'1982-02-23', '2009-04-28', NULL, '0', '1');
INSERT INTO `personal` VALUES ('41352619', 'Yessenia Clariza', 'Rodas Correo', 'clave2' , '1989-01-09', '2009-04-28', NULL, '1', '1');
INSERT INTO `personal` VALUES ('42751388', 'Pedro Ricardo', 'Mariano Jimenz', 'clave3' , '1984-12-20', '2009-04-28', NULL, '1', '1');
CitarAppserver/
|--- www/
|--- web/
| |--- ajax/ (Js ^^', alquien se dio cuenta?)
| | |--- home.js (ajax)
| |--- clases/ (clases php ^^')
| | |--- mysql.php (clase de conexion)
| | |--- personal.php (clase para personal)
| | |--- ingreso.php (clase funciones)
| |--- imagenes/ (imagenes)
| | |--- loader.gif (icono cargando)
| |--- index.php (pagina de inicio)
<?
//Clase Mysql, se usa para la conexion a la Base de Datos
class Mysql
{
var $conexion;
//inicia conexion con el servidor
function conecta()
{
if(!isset($this->conexion))
{
$ser = "localhost"; //servidor
$usr = "root"; //usuario
$pwd = "root"; //password
$bbd = "sistema"; //base de datos
$this->conexion = (mysql_connect($ser,$usr,$pwd)) or die(mysql_error());
mysql_select_db($bbd,$this->conexion) or die(mysql_error());
}
}
//realiza la consulta recepcionada
function consulta($consulta)
{
$resultado = mysql_query($consulta,$this->conexion);
if(!$resultado)
{
echo 'MySql Error: '.mysql_error();
exit;
}
return $resultado;
}
//devuelve un vector de la consulta
function vector($consulta)
{
return mysql_fetch_array($consulta);
}
//retorna el numero de registros para la consulta
function filas($consulta)
{
return mysql_num_rows($consulta);
}
}
?>
<?
class Persona
{
var $p_idpersona;
var $p_nombre;
var $p_apellido;
var $p_persona;
var $p_imagen;
var $p_sexo;
var $p_fecnac;
var $p_estado;
var $p_existe;
//function que define si el idpersona existe
function set_idpersona($codigo,$clave)
{
include("mysql.php");
$sql = "select * from personal where idpersonal='$codigo' and clave='$clave'";
$con = new Mysql();
$con->conecta();
$res = $con->consulta($sql);
$num = $con->filas($res);
if($num>0)
{
$row = $con->vector($res);
$this->p_idpersona=$codigo;
$this->p_nombre=$row['nombres'];
$this->p_apellido=$row['apellidos'];
$this->p_imagen=$row['imagen'];
$this->p_sexo=$row['sexo'];
$this->p_estado=$row['estado'];
$this->p_fecnac=$row['fecnac'];
$this->p_persona=$this->p_apellido.', '.$this->p_nombre;
$this->p_existe=1;
}
else
{
$this->p_existe=0;
}
}
//Retorna true si el usuario existe, caso contrario false
function get_existe()
{
return $this->p_existe;
}
//Retorna el codigo de la persona
function get_idpersona()
{
return $this->p_idpersona;
}
//Retorna el nombre de la persona
function get_nombre()
{
return $this->p_nombre;
}
//Retorna el apellido de la persona
function get_apellido()
{
return $this->p_apellido;
}
//Retorna el sexo de la persona
function get_sexo()
{
return $this->p_sexo;
}
//Retorna la imagen de la persona
function get_imagen()
{
return $this->p_imagen;
}
//Retorna la fecha de nacimiento de la persona
function get_fecnac()
{
return $this->p_fecnac;
}
//Retorna el estado de la persona
function get_estado()
{
return $this->p_estado;
}
//Retorna el nombre completo de la persona
function get_persona()
{
return $this->p_persona;
}
}
?>
<?
include("persona.php");
$usuario = $_REQUEST['usu'];
$clave = $_REQUEST['pwd'];
$usu = new Persona();
$usu->set_idpersona($usuario,$clave);
$est = $usu->get_existe();
if($est==1){
?>
Llamar a funcion javascript que llame a la pagina principal.
APORTE PARA LA COMUNIDAD FORO.ELHACKER.NET
saludos.
<? }else{ ?>
Usuario <input type="text" id="usr" name="usr" maxlength="8" /><br>
clave <input type="text" id="pwd" name="pwd" maxlength="25" /><br>
<input type="button" value="Ingresar" onclick="verifica();"/><br><br>
<center>Datos incorrectos</center>
<? } ?>
//Funcion para ajax
function NewAjax()
{
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined')
{
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
//Funcion para el login
function verifica()
{
var usu = document.getElementById('usr');
var pwd = document.getElementById('pwd');
var div = document.getElementById('cuerpo');
var ajax = NewAjax();
ajax.open("POST", 'clases/ingreso.php?usu='+usu.value+'&pwd='+pwd.value,true);
ajax.onreadystatechange=function()
{
if (ajax.readyState==4)
{
var ok = ajax.responseText;
div.innerHTML = ok;
}
else
{
div.innerHTML = "<img src='imagenes/loader.gif'><br><br><font color='#666666'>Autentificando<br>Espere un momento por favor.</font>";
}
}
ajax.send(null);
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ingreso : Aporte para foro.elhacker.net</title>
<script src="ajax/home.js" language=" javascript" type="text/ javascript"></script>
</head>
<body>
<div id='cuerpo' name='cuerpo'>
Usuario <input type="text" id="usr" name="usr" maxlength="8" /><br>
clave <input type="text" id="pwd" name="pwd" maxlength="25" /><br>
<input type="button" value="Ingresar" onclick="verifica();"/>
</div>
</body>
</html>
ob_start();
include "conexion.php";
include "funciones.php";
require_once('class.ezpdf.php');
$pdf =& new Cezpdf('a4');
$pdf->selectFont('../fonts/courier.afm');
$pdf->ezSetCmMargins(1,1,1.5,1.5);
$sql = "select producto, precio from producto";
$res = mysql_query($sql);
$num = mysql_num_rows($res);
$ixx = 0;
while($datatmp = mysql_fetch_assoc($res)) {
$ixx = $ixx+1;
$data[] = array_merge($datatmp, array('num'=>$ixx));
}
$titles = array(
'producto'=>'<b>producto</b>',
'precio'=>'<b>Precio</b>'
);
$options = array(
'shaded'=>0,
'fontSize'=> 8,
'showLines'=>2,
'xOrientation'=>'center',
'width'=>550,
);
$txttit = "<b>relacion</b>\n";
$pdf->ezText($txttit, 12);
$pdf->ezTable($data, $titles, '', $options);
$pdf->ezText("\n\n\n", 10);
$pdf->ezText("<b>Fecha:</b> ".date("d/m/Y"), 10);
$pdf->ezText("<b>Hora:</b> ".date("H:i:s")."\n\n", 10);
$pdf->ezStream();
ob_flush();
$res = mysql_query($sql);
Dim a as String
a = "Esto es una prueba"
msgbox(a.substring(0,2))
Citarcreate database prueba
use prueba
create table usuario(id_usuario int primary key,usuario varchar(30),telefono varchar(9),estado char(1))
insert into usuario values (1,'us1','121212','1')
insert into usuario values (2,'us2','213232','0')
insert into usuario values (3,'us3','434343','1')
insert into usuario values (4,'us4','454545','0')
insert into usuario values (5,'us5','654545','1')
insert into usuario values (6,'us6','754546','0')
insert into usuario values (7,'us7','854547','1')
insert into usuario values (8,'us8','854547','0')
insert into usuario values (9,'us9','954549','1')
CitarImports System.IO
Imports System.Collections
Imports System.Data.SqlClient
Public Class Form1
Private con As New SqlConnection("integrated security=sspi;data source=(local);initial catalog=master")
Private cmd As SqlCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim RutaArchivo As New StreamReader("C:\archivo.txt")
Dim total As Integer
While Not RutaArchivo.EndOfStream
total += 1
RutaArchivo.ReadLine()
End While
Me.ProgressBar1.Minimum = 0
Me.ProgressBar1.Maximum = total
Me.BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Try
Dim CalculoTiempo As New Stopwatch
Dim RutaArchivo As New StreamReader("C:\archivo.txt")
Dim porcentaje As Integer
Dim linea As String
While Not RutaArchivo.EndOfStream
If BackgroundWorker1.CancellationPending Then
Exit While
End If
CalculoTiempo.Reset()
CalculoTiempo.Start()
linea = RutaArchivo.ReadLine()
porcentaje += 1
cmd = New SqlCommand(linea, con)
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
BackgroundWorker1.ReportProgress(porcentaje)
CalculoTiempo.Stop()
Threading.Thread.Sleep(CalculoTiempo.ElapsedMilliseconds)
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
Label1.Text = "Ejecutados " & e.ProgressPercentage & " de " & Me.ProgressBar1.Maximum
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Label2.Text = "Proceso completado"
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
con.Close()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con.Open()
End Sub
End Class
CitarDim CalculoTiempo As New Stopwatch
Citar While Not RutaArchivo.EndOfStream
CalculoTiempo.Reset() 'Reseteamos el tiempo para la variable
CalculoTiempo.Start() 'iniciamos el valor para calcular el tiempo
linea = RutaArchivo.ReadLine() ' leemos la linea de la sentencia sql
porcentaje += 1 'aumentamos el porcentaje del progessbarr
cmd = New SqlCommand(linea, con) 'instanciamos la consulta en el sqlcommand
cmd.CommandType = CommandType.Text 'definimos el tipo de comando
cmd.ExecuteNonQuery() 'ejecutamos el comando
BackgroundWorker1.ReportProgress(porcentaje) 'enviamos el porcentaje al evento ProgressChanged del BackgroundWorker.
CalculoTiempo.Stop() 'detenemos el conteo de tiempo del proceso
Threading.Thread.Sleep(CalculoTiempo.ElapsedMilliseconds) 'pausa
End While
Citar Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
Label1.Text = "Ejecutados " & e.ProgressPercentage & " de " & Me.ProgressBar1.Maximum
End Sub
Citar