Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/10/2008, 10:21
cancha
 
Fecha de Ingreso: junio-2007
Mensajes: 75
Antigüedad: 16 años, 10 meses
Puntos: 1
problema con atributos estaticos....

Tengo una pagina llamada interface.php desde la cual trabajo con los atributos estaticos de la clase Persona mediante los metodos de la clase Mantenimiento
los atributos son arrays pero solo puedo ingresar un dato y no puedo pasar al siguiente indice para ingresar mas datos..
este es el codigo....

Persona.php
Código:
<?php
	class Persona{
		public static $id=array();
		public static $pat=array();
		public static $mat=array();
		public static $nom=array();
		public static $edad=array();
		public static $sexo=array();
	}
?>
Mantenimiento.php
Código:
<?php require_once("persona.php");
	class Mantenimiento extends Persona{
		public static function agregar($newid,$newpat,$newmat,$newnom,$newedad,$newsexo){
			$i=count(parent::$id);
			echo $i;//siempre me devuelve 0 
			parent::$id[$i]=$newid;
			parent::$pat[$i]=$newpat;
			parent::$mat[$i]=$newmat;
			parent::$nom[$i]=$newnom;
			parent::$edad[$i]=$newedad;
			parent::$sexo[$i]=$newsexo;
		}
		public static function modificar($newid,$newpat,$newmat,$newnom,$newedad,$newsexo){
			for($i=0;$i<count(parent::$id);$i++){
				if(parent::$id[$i]==$newid){
					parent::$pat[$i]=$newpat;
					parent::$mat[$i]=$newmat;
					parent::$nom[$i]=$newnom;
					parent::$edad[$i]=$newedad;
					parent::$sexo[$i]=$newsexo;
					break;
				}
			}
		}
	}
?>
interface.php
Código:
<!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=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>
<?php
	require_once("mantenimiento.php");//esto no es el problema cuando envio los datos del formulario no se vuelve a escribir mantenimiento.php borrando los datos que se ingresaron...?
?>
<body>
<?php
	if(empty($_POST['txtid'])){
		crearform("","","","","","");
	}else if($_REQUEST['rbtop']=="add"){
		mantenimiento::agregar($_REQUEST['txtid'],$_REQUEST['txtpat'],$_REQUEST['txtmat'],$_REQUEST['txtnom'],$_REQUEST['txtedad'],$_REQUEST['txtsexo']);
		echo 'Datos Agregados';
		crearform($_REQUEST['txtid'],$_REQUEST['txtpat'],$_REQUEST['txtmat'],$_REQUEST['txtnom'],$_REQUEST['txtedad'],$_REQUEST['txtsexo']);
	}else if($_REQUEST['rbtop']=="del"){
		
	}else if($_REQUEST['rbtop']=="mod"){
		
	}else if($_REQUEST['rbtop']=="srch"){
		
	}

	function crearform($nid,$npat,$nmat,$nnom,$nedad,$nsexo){
		echo	'<form name="frm1" action="interface.php" method="post">
					<table align="center" border="1">
						<tr>
							<td>ID</td>
							<td><input type="text" name="txtid" value="'.$nid.'"/></td>
						</tr>
						<tr>
							<td>Paterno</td>
							<td><input type="text" name="txtpat" value="'.$npat.'"/></td>
						</tr>
						<tr>
							<td>Materno</td>
							<td><input type="text" name="txtmat" value="'.$nmat.'"/></td>
						</tr>
						<tr>
							<td>Nombre</td>
							<td><input type="text" name="txtnom" value="'.$nnom.'"/></td>
						</tr>
						<tr>
							<td>Edad</td>
							<td><input type="text" name="txtedad" value="'.$nedad.'"/></td>
						</tr>
						<tr>
							<td>Sexo</td>
							<td><input type="text" name="txtsexo" value="'.$nsexo.'"/></td>
						</tr>
						<tr>
							<td colspan="2">
								Agregar<input type="radio" name="rbtop" value="add">
								Eliminar<input type="radio" name="rbtop" value="del">
								Modificar<input type="radio" name="rbtop" value="mod">
								Buscar<input type="radio" name="rbtop" value="srch">
							</td>
						</tr>
						<tr>
							<td colspan="2" align="center">
								<input type="submit" name="btnsend" value="Enviar"/>
							</td>
						</tr>
					</table>
				</form>';
	}
?>
</body>
</html>