Os dejo el código de la aplicación:
Código PHP:
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/xajax/xajax_core/xajax.inc.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MySQL.php');
$obj=new xajax();
$obj->configure('characterEncoding','ISO-8859-1');
$obj->configure('decodeUTF8Input',true);
$obj->configure('javascript URI','/lib/xajax/');
($db=DataBase::getInstance()) or die (mysql_error());
function construye_tabla($id)
{
$oficios=array('','EMPLEADO','VENDEDOR','DIRECTOR','ANALISTA','PRESIDENTE');
$query="SELECT emp_no,apellido,dir,fecha_alt,salario,comision,dept_no";
$query.="FROM emple";
$query.="WHERE oficio LIKE '".$oficios[$id]."'";
if ($db->setQuery($query))
{
$empleados=$db->loadObjectList();
$new_tabla='<table>';
$new_tabla.='<tr>';
$new_tabla.='<td class="b2">emp_no</td>';
$new_tabla.='<td class="b2">apellido</td>';
$new_tabla.='<td class="b2">dir</td>';
$new_tabla.='<td class="b2">fecha_alt</td>';
$new_tabla.='<td class="b2">salario</td>';
$new_tabla.='<td class="b2">comision</td>';
$new_tabla.='<td class="b2">dept_no</td>';
$new_tabla.='</tr>';
foreach ($empleados as $emple)
{
$new_tabla.='<tr>';
$new_tabla.='<td class="b1">'.$emple->emp_no.'</td>';
$new_tabla.='<td class="b1">'.$emple->apellido.'</td>';
$new_tabla.='<td class="b1">'.$emple->dir.'</td>';
$new_tabla.='<td class="b1">'.$emple->fecha_alt.'</td>';
$new_tabla.='<td class="b1">'.$emple->salario.'</td>';
$new_tabla.='<td class="b1">'.$emple->comision.'</td>';
$new_tabla.='<td class="b1">'.$emple->dept_no.'</td>';
$new_tabla.='</tr>';
}
$new_tabla.='</table>';
}
else
$new_tabla=0;
return $new_tabla;
}
function generar_tabla($in)
{
$respu=new xajaxResponse();
if ($in)
{
if ($out=construye_tabla($in))
{
$respu->assign('divmsj','innerHTML','Consulta realizada con éxito');
$respu->assign('divtabla','innerHTML',$out);
}
else
$respu->assign('divmsj','innerHTML','Error en la consulta');
}
else
$respu->assign('divmsj','innerHTML','No has seleccionado ningún oficio');
return $respu;
}
$obj->register(XAJAX_FUNCTION,'generar_tabla');
$obj->processRequest();
Código:
<br/><br/> <div id="divmsj" class="msj"> Selecciona el oficio a buscar: </div> <br/> <div id="divform" class="b1"> <form id="formulario" accept-charset="utf-8" action='<?php $PHP_SELF ?>'> <select name="oficios" onchange="xajax_generar_tabla(document.formulario.oficios.options[document.formulario.oficios.selectedIndex].value)"> <option value="0">--SELECCIONA UN OFICIO--</option> <option value="1">EMPLEADO</option> <option value="2">VENDEDOR</option> <option value="3">DIRECTOR</option> <option value="4">ANALISTA</option> <option value="5">PRESIDENTE</option> </select> <br/><br/> </form> </div> <br/><br/> <div id="divtabla" class="c1"> </div> <br/><br/>