Search Postgresql Archives

RES: Ajax/PostgreSQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Paul : 

You can use deferred load do this.

I am using tu active /deactive user without open a window and going to other
page and return.
No ajax in this code.

----------------------------------
// This is in the user form...
----------------------------------
<head>
<script type="text/javascript" src="../js/cargadiferida.js"></script>
</head>

<script type="text/javascript">

function AtivaDesativar( sDescricao, nIdUsuario )
{
if ( confirm(" Deseja Ativar / Desativar o Usuário " +  sDescricao + " ? " )
)
{
	// This make the call to a php file that work with pg.
    RealizarPeticao( "usuarios_ativardesativar.php?idusuario=" + nIdUsuario
); 
} else 
    return false;

}

}
</script>

-------------------------------
This is the cargadiferida.js:
-------------------------------
function RealizarPeticao( sPagina )
{

if ( sPagina.trim() == '' )
    return '';

// Create a new element script...
var oScript = document.createElement( 'script' );

// Put the source page.
// Some like this "usuarios_ativardesativar.php?idusuario=10";
oScript.src = sPagina;

// Y add the new script tag to the body....
document.body.appendChild( oScript );

}

// This is to chage the image in the list.
function ProcessarRespostaAtivacao( sNomeTag, sClase )
{

if ( sNomeTag.trim() == '' )
    return '';

oResultado           = document.getElementById( sNomeTag.trim() );
oResultado.className = sClase;

}

----------------------------------------------
This is the php file, usuarios_ativardesativar.php :
----------------------------------------------

<?php
header("Content-type: text/javascript"); // Note that the output is
javascript...

require_once( '../comun/cabecalho.php' );

$sSql  = " SELECT CASE WHEN ativo = 1 THEN 0 ELSE 1 END AS ativo ";
$sSql .=   " FROM os_usuarios ";
$sSql .=  " WHERE idusuairo = {$_REQUEST['idusuario]} ";
$sSql .=    " AND idempresa = {$_SESSION['empresa_session']} ";

$rs = $Connection->Execute( $sSql );

if ( !$rs )
    Error_Msg( ' Erro : ao Atualizar => ', $Connection->ErrorMsg(), $sSql );

if ( !$rs->EOF )
{
    if ( $rs->fields['ativo'] == 0 )
        $sClase = 'ativar';
    else
        $sClase = 'desativar';

    $sSql  = " UPDATE os_usuarios ";
    $sSql .=    " SET ativo = {$rs->fields['ativo']} ";
    $sSql .=  " WHERE idusuario = {$_REQUEST['idusuario']} ";
    $sSql .=    " AND idempresa = {$_SESSION['empresa_session']} ";

    $rs = $Connection->Execute( $sSql );

    if ( !$rs )
        Error_Msg( ' Erro : ao Atualizar => ', $Connection->ErrorMsg(),
$sSql );

?>
// This is a call to ProcessarRespostaAtivacao, note this is a javascript
funcion. 
ProcessarRespostaAtivacao( '<?php echo "cmd{$_REQUEST['idusuario']}"; ?>',
'<?php echo $sClase; ?>' );

<?php } ?>


I test this in Firefox and ie. I have no problem to execute this code.

Alejandro Michelin Salomon
Porto Alegre
Brasil.

-->-----Mensagem original-----
-->De: pgsql-general-owner@xxxxxxxxxxxxxx 
-->[mailto:pgsql-general-owner@xxxxxxxxxxxxxx] Em nome de Paul M Foster
-->Enviada em: sábado, 5 de agosto de 2006 19:43
-->Para: pgsql-general@xxxxxxxxxxxxxx
-->Assunto: [GENERAL] Ajax/PostgreSQL
-->
-->
-->I'm doing some massive (internal company) applications using 
-->PHP, which 
-->query extensive PostgreSQL tables. This is fine, but 
-->obviously it often 
-->requires multiple web pages to get something done. Supposedly, AJAX 
-->promises to make web pages more interactive. But from what I 
-->understand, 
-->I'd have to have bindings from Javascript into PostgreSQL to 
-->make this work.
-->
-->Here's an example: The user wants to enter a bill (accounts payable) 
-->into the system. He first has to pick a vendor. Normally, this would 
-->entail a PHP page that generates a PostgreSQL query. The 
-->user would then 
-->get a second page with various vendor information (like 
-->number of due 
-->days for that vendor), and various other payable info. But 
-->wouldn't it 
-->be nice to have vendor information filled in on the original page, 
-->directly after the user picks a vendor? Theoretically, AJAX 
-->might allow 
-->something like this. But from what I can see, it would require 
-->PostgreSQL bindings in Javascript, and some way to pass the 
-->data back so 
-->that PHP could use it.
-->
-->Is this even possible? Is it being worked on? Is there a different 
-->solution I don't know about? I can see where Javascript can 
-->alter the 
-->look of a page, but I can't work out how it would allow 
-->interactive use 
-->of a PostgreSQL table.
-->
-->-- 
-->Paul M. Foster
-->
-->---------------------------(end of 
-->broadcast)---------------------------
-->TIP 9: In versions below 8.0, the planner will ignore your desire to
-->       choose an index scan if your joining column's datatypes do not
-->       match
-->



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux