PHP Classes

adaptacion

Recommend this page to a friend!

      PHP 4 Applications  >  All threads  >  adaptacion  >  (Un) Subscribe thread alerts  
Subject:adaptacion
Summary:adaptacion para realizar consultas, updates y eliminar
Messages:8
Author:Julieta
Date:2005-02-07 18:06:46
Update:2005-02-08 19:55:06
 

  1. adaptacion   Reply   Report abuse  
Picture of Julieta Julieta - 2005-02-07 18:06:47
hola frannauta, me gustaria que me respondieras esta pregunta:

quiero utilizar remote scripting para agregar datos a la base de datos y me muestre el dato en la misma pagina, se entiende, no?

el dato que tiene que entrar a la base de datos es un textbox.

tiene que ser algo práctico como para agregar varias variables, digamos varios textbox.

y tambien tiene que ser practico como para adaptar el sistema para agregar como para eliminar y actualizar.

Saludos!, y excelente script.

  2. Re: adaptacion   Reply   Report abuse  
Picture of Julieta Julieta - 2005-02-07 21:16:11 - In reply to message 1 from Julieta
cree algo como esto:

ig2producciones.com.ar/inmoby/admin ...

faltaria adornarlo con algun cargado y seguro despues a la adpatacion de otro sistema mas complejo se presentaran algunas complicaciones

ustedes que dicen?

  3. Re: adaptacion   Reply   Report abuse  
Picture of Julieta Julieta - 2005-02-08 04:05:25 - In reply to message 2 from Julieta
bueno, les comento que el sistema que yo cree ya presenta complicaciones...

ahora si yo quiero eliminar un dato... tengo que hacer uso de los IDs... como

si quiero hacer un update tambien, y esto esta bueno, porque si quiero cambiar algo, tengo que hacer click en modificar y que me aparezca en textbbox con el campo libre para cambiar el dato...

es complicado, les dejo aca un zip con los 4 archivos que hice

ig2producciones.com.ar/remote.zip

  4. Re: adaptacion   Reply   Report abuse  
Picture of Julieta Julieta - 2005-02-08 04:10:39 - In reply to message 3 from Julieta
aca les mando el archivo sql

ig2producciones.com.ar/duenos.sql

  5. Re: adaptacion   Reply   Report abuse  
Picture of Francisco Arias Francisco Arias - 2005-02-08 13:05:51 - In reply to message 1 from Julieta

Para utilizar remote scripting en tu programa deberías modificar el index.php de la manera siguiente:

1.En el formulario poner que el "target" es el iframe de la manera siguiente:

<form name="form1" onsubmit="send_post(this.name); display_response(); return false;" TARGET="MyRemoteFrame">


2.El script de carga de datos "inc_datos.php" deberá devolver los datos refiriendose al div "responseContainer" de la manera siguiente:

parent.responseContanier.innerHTML =" .... " y dentro del innerHTML todo el codigo que quieras que se vea


3.además, en el index.php deberás incluir la siguiente línea antes del </body>

<iframe style="width:0px; height:0px" marginwidth=0 marginheight=0 frameborder="no" id="MyRemoteFrame" name="MyRemoteFrame"></iframe>



te mando los scripts modificados para que los estudies

INDEX.PHP******************************************************************************

<?php require( "../../variables.php" );
dbConnect();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<link href="../estilosadmin_iframe.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="funciones.js"></script>
<head>
<title>Remote Scripting Example</title>
</head>
<body>
<!-- note: form must be named! -->
<form name="form1" onsubmit="send_post(this.name); display_response(); return false;">
<p>Agregar dato a la base:
<input type="text" name="nombre" value="">
<input type="submit" value="metele pata">
</p>
</form>
<div id="responseContainer"></div>

<iframe style="width:0px; height:0px" marginwidth=0 marginheight=0 frameborder="no" id="MyRemoteFrame" name="MyRemoteFrame"><?php include("inc_datos.php");?></iframe>

</body>
</html>

INC_DATOS.PHP **********************************************************************************************

<table width="100%" border="0" cellspacing="0" cellpadding="3">
<?php
$tabla2 = $dbPref."duenos";
$consulta2 = mysql_query( "SELECT * FROM $tabla2 ORDER BY nombre ASC" ) ;
$i = 1;


$html = "<script>parent.responseContainer.innerHTML='";



while ($renglon = mysql_fetch_array( $consulta2 ))
{
$i % 2 == 0 ? $bgColor = "#FFFFFF" : $bgColor = $colorLista;
$html .= "<tr bgcolor=\"".$bgColor."\">";
$html .= "<td><P>\n";
$html .= $renglon[nombre]."</p>\n";
$html .= "</td>";
$html .= "</tr>";
$i++;
}

$html .= "';</script>";

echo $html;
?>
</table>

  6. Re: adaptacion   Reply   Report abuse  
Picture of Julieta Julieta - 2005-02-08 19:01:16 - In reply to message 5 from Francisco Arias
te paso el inc_datos para que veas como quiero seguir el programa

como vos me lo mandaste anda, me mete los datos en la base de datos y anda bien el remote, pero no me muestra los datos.

////inc_datos.php

<table width="100%" border="0" cellspacing="0" cellpadding="3">
<?php
$tabla2 = $dbPref."duenos";
$consulta2 = mysql_query( "SELECT * FROM $tabla2 ORDER BY nombre ASC" ) ;
$i = 1;

$html = "<script>parent.responseContainer.innerHTML='";

while ($renglon = mysql_fetch_array( $consulta2 ))
{
$i % 2 == 0 ? $bgColor = "#FFFFFF" : $bgColor = $colorLista;
$html .= "<tr bgcolor=\"".$bgColor."\">";
$html .= "<td><P>\n";
$html .= $renglon[nombre]."</p>\n";
$html .= "</td>";
//celda que tiene el form para luego eliminar
$html .= "<td width=\"90\">";
$html .= "<form name=\"form$renglon[iddueno];\" onsubmit=\"send_post(this.name); display_response(); return false;\">";
$html .= "<input type=\"hidden\" value=\"$renglon[iddueno];\"><input type=\"button\" value=\"Eliminar\" />";
$html .= "</form>";
$html .= "</td>";

$html .= "</tr>";
$i++;
}

$html .= "';</script>";

echo $html;
?>
</table>


/////funciones.js
// load the appropriate xmlHttpRequest for IE or Mozilla
// this sniffer code can be found at
// http://jibbering.com/2002/4/httprequest.html
var xmlHttp

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
xmlHttp=false
}
}
@else
xmlHttp=false
@end @*/
if (!xmlHttp) {
try {
xmlHttp = new XMLHttpRequest();
}
catch (e) {
xmlHttp=false
}
}

// end jibbering.com code


// the php script to process the form. var must be global!

var URLto = 'process.php';
// function to build POST requests

function buildPOST(theFormName) {
theForm = document.forms[theFormName];
var qs = ''
for (e=0;e<theForm.elements.length;e++) {
if (theForm.elements[e].name!='') {
var name = theForm.elements[e].name;
qs+=(qs=='')?'':'&'
qs+= name+'='+escape(theForm.elements[e].value);
}
}
qs+="\n";
return qs
}

// function to communicate with remote script

function send_post(theFormName) {
var xmlMessage = buildPOST(theFormName);
xmlHttp.open("POST", URLto, false)

// for ie compatability
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(xmlMessage)
}

function display_response() {
var optionDiv = document.getElementById("responseContainer");
optionDiv.innerHTML = xmlHttp.responseText;
}

////index.php
<?php require( "../../variables.php" );
dbConnect();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<link href="../estilosadmin_iframe.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="funciones.js"></script>
<head>
<title>Remote Scripting Example</title>
</head>
<body>
<!-- note: form must be named! -->
<form name="form1" onsubmit="send_post(this.name); display_response(); return false;">
<p>Agregar dato a la base:
<input type="text" name="nombre" value="">
<input type="submit" value="metele pata">
</p>
</form>
<div id="responseContainer"></div>

<iframe style="width:0px; height:0px" marginwidth=0 marginheight=0 frameborder="no" id="responseContainer" name="responseContainer"><?php include("inc_datos.php");?></iframe>

</body>
</html>



Nota: fijate en eliminar, lo plantie de esa manera, que tampoco anda, o no se porque no me muestra los datos... es un lio terrible terrible, pero hagamoslo que puede servir para mucha gente

Saludos.

  7. Re: adaptacion   Reply   Report abuse  
Picture of Julieta Julieta - 2005-02-08 19:11:51 - In reply to message 6 from Julieta
me falto lo más importante!

te mando los archivos con los script que tiene que hacer el sistema

acordate que cuando el se agrega algo o se elimina yo tengo que ir viendo el resultado

//process.php aca estoy agregando
<?php
//Llamo a la página con las variables de conexión
require( "session.php" );

//Agrego a la tabla
$nombre = $_POST['nombre'];
$tabla = $dbPref."duenos";
$agregar = "INSERT INTO $tabla VALUES ('', '$nombre')";
$ejecutar = mysql_query ($agregar) or error( mysql_error() );

echo "<p>Se agregó exitosamente <strong>$nombre</strong>, exitosamente, porque no existen errores</p>";
?>
<?php include("inc_datos.php");?>


//process_eliminar, esto no lo uso, pero es la idea para que vea lo que tiene que hacer

<?php

//Llamo a la página con las variables de conexión
require( "session.php" );

//Agrego a la tabla
$iddueno = $_POST['iddueno'];
$tabla = $dbPref."duenos";
$ejecutar = mysql_query( "DELETE FROM $tabla WHERE iddueno='$iddueno' " ) or error( mysql_error() );
}
//de alguna manera me tiene que eliminar la fila
?>
<?php include("inc_datos.php");?>

  8. Re: adaptacion   Reply   Report abuse  
Picture of Julieta Julieta - 2005-02-08 19:55:06 - In reply to message 7 from Julieta
el inc_datos es solo la pagina que muestra los datos

el inc_datos se tiene que mostrar en el index, y cuando ejecuto el process.php se tiene que mostrar actualizado sin refrescar la página

tengan en cuenta que el process.php no es lo unico que tiene que hacer, sino tambien tiene que hacer el process_eliminar y otra pagina más para hacer el update, hay que crear algo práctico para poder hacer varias funciones

PD; echenle un vistado al funciones.js+

Saludos.