Este é um exemplo da divisão de tarefas que criei para acesso e atualização de dados de um banco de dados, tabela Departamento Arquivo frmDepFrame.php
<FRAMESET ROWS="60%,*">
<FRAME SRC="frmDepGrid.php" NAME="GridDep" SCROLLING="yes" NORESIZE FRAMEBORDER='0'></FRAME>
<FRAME SRC="frmDep.php" NAME="Corpo" NORESIZE FRAMEBORDER='0'></FRAME>
Arquivo frmDepGrid.php
<?
include "objDB.php";
include "objGrid1.php";
$grd = new obj_grid();
$sql = "SELECT dep_id, dep_dsc FROM obj_dep ORDER BY dep_dsc";
$grd->setSQL($sql);
$grd->setTitulo(" Departamento ");
?>
<HTML>
<HEAD>
<TITLE>Objeto</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="obj.css">
<SCRIPT Language="Javascript">
function Sele(inDepId, inDepDsc){
parent.Corpo.frmDep.dep_id.value = inDepId;
parent.Corpo.frmDep.dep_dsc.value = inDepDsc;
}
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<?=$grd->Grid();?>
</CENTER>
</BODY>
</HTML>
</FRAMESET>
Arquivo frmDep.php
<HTML>
<HEAD>
<LINK REL="stylesheet" TYPE="text/css" HREF="obj.css">
<SCRIPT Language="Javascript">
function Envia(inOpt){
document.frmDep.opt.value = inOpt;
Valida();
}
function Valida(){
var conf = true;
var msg = "";
if (document.frmDep.dep_dsc.value == ""){
msg = " Descrição";
conf = false;
}
if (!conf){
alert("Departamento: Erro na(o):" + msg);
} else {
document.frmDep.submit();
}
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#bbccdd">
<CENTER><FONT SIZE='+1'><B>Departamento</B></FONT>
<FORM NAME="frmDep" ACTION="DepExe.php" METHOD="post">
<INPUT TYPE="hidden" NAME="opt">
<TABLE>
<TR>
<TD>Número</TD>
<TD><INPUT TYPE="text" NAME="dep_id" VALUE=""></TD>
</TR>
<TR>
<TD>Descrição</TD>
<TD><INPUT TYPE="text" NAME="dep_dsc" VALUE="" SIZE='50'></TD>
</TR>
</TABLE>
<TABLE WIDTH="60%">
<TD CLASS="botao" WIDTH="20%"><A HREF="#" onClick="Envia('Pro');">Procurar</A></TD>
<TD CLASS="botao" WIDTH="20%"><A HREF="#" onClick="Envia('Inc');">Incluir</A></TD>
<TD CLASS="botao" WIDTH="20%"><A HREF="#" onClick="Envia('Alt');">Alterar</A></TD>
<TD CLASS="botao" WIDTH="20%"><A HREF="#" onClick="Envia('Exc');">Excluir</A></TD>
<TD CLASS="botao" WIDTH="20%"><A HREF="#" onClick="parent.location = 'frmObj.htm';">Sair</A></TD>
</TABLE>
</FORM>
</CENTER>
</BODY>
</HTML>
Arquivo objDep.php
<?
class obj_dep{
var $dep_id;
var $dep_dsc;
function setId($dep_id){
$this->dep_id = $dep_id;
}
function setDsc($inDsc){
$this->dep_dsc = $inDsc;
}
function getId(){
return $this->dep_id;
}
function getDsc(){
return $this->dep_dsc;
}
function IncluiDep(){
include "objDB.php";
$db = new obj_db();
$sql = "INSERT INTO obj_dep (dep_dsc) VALUES ('".$this->getDsc()."')";
$result = $db->exec_sql($sql);
unset($result);
}
function AlteraDep(){
include "objDB.php";
$db = new obj_db();
$sql = "UPDATE obj_dep SET dep_dsc = '".$this->getDsc()."' WHERE dep_id = ".$this->getId();
$result = $db->exec_sql($sql);
unset($result);
}
function ExcluiDep(){
include "objDB.php";
$db = new obj_db();
$sql = "DELETE FROM obj_dep WHERE dep_id = ".$this->getId();
$result = $db->exec_sql($sql);
unset($result);
}
function ProcuraDep(){
include "objDB.php";
$db = new obj_db();
$sql = "SELECT * FROM obj_dep WHERE dep_id = ".$this->getId();
$result = $db->exec_sql($sql);
if ($result){
$query_data = mysql_fetch_array($result);
$this->setDsc($query_data["dep_dsc"]);
}
unset($result);
}
}
?>