Ver Mensaje Individual
  #2 (permalink)  
Antiguo 26/05/2010, 19:28
bras111
 
Fecha de Ingreso: mayo-2010
Mensajes: 2
Antigüedad: 14 años
Puntos: 0
Respuesta: Error que me esta dejando loco

CODIGO TAULA_SQL
Código PHP:
<?            
/*    PARÀMETRES GENERALS
        1. "operacio"     => opció del switch principal    

    PARÀMETRES GRÀFICS
        2. "class"          => estil de la taula 
        3. "estil_href"   => estil dels links
        4. "colors_alt"      => colors de les files alterantius
        5. "ws"              => (array) amplada de cada columna
        6. "titols"          => (array) títol de cada columna
        7. "imatges"      => (array) imatges que actuen com a link. S'ha d'indicar per ordre ( títol columna, amplada columna, imatge, link i nº de camp de la bbdd que li passen al link )        

    PARÀMETRES SQL
        8. "tipus"          => si la bbdd és MySQL o PostgreeSQL
        9. "sql"          => consulta sql
       10. "paraula"      => paraula que serveix de filtre. El camp que actual de filtre el determina el paràmetre "$sql"
       11. "ordre"        => ordre de la taula ( forçat per GET )        
       12. "n_resultats"  => nº de files de la taula       
       13. "taula"          => indica de quina taula s'esborrarà el registre amb id = al paràmetre "$delete"        
       14. "delete"          => id de "$taula" que s'ha de borrar              

    PARÀMETRES DELS LINKS
          15. "titols_ordre" => link dels títols per a ordenar per columnes    
       16. "url_link"      => link a una altra pàgina a la que passem un paràmetre 
       17. "camp_link"      => (array) nº del camp de la consulta sql que es passa com a paràmetre a un link               */

function taula_sql $operacio,      
                     
$class,          
                     
$estil_href,      
                     
$colors_alt,      
                     
$ws,  
                     
$titols,      
                     
$imatges,
                     
$tipus,
                     
$sql,                     
                     
$paraula,        
                     
$ordre,        
                     
$n_resultats,        
                     
$taula,        
                     
$delete,        
                     
$titols_ordre,    
                     
$url_link,
                     
$camp_link     )        

    
//1 - PARÀMETRES A ARRAYS                                    //converteixo els paràmetres en arrays, per a poder treballar millor a l'hora de tractar
    
$ws_ split","$ws );                                    //columna per columna
    
$titols_ split","$titols );
    
$url_link_split","$url_link );
    
$camp_link_ split","$camp_link );
    
$imatges_ split","$imatges );
    
$ordres_ split","$titols_ordre );
    
$color_ split","$colors_alt );

//echo $sql;
    //Abans de crear la taula, si rebo el paràmetre DEL, elimino el registre corresponent 
    
if ($delete != "") {
        if (
$tipus == "my") {
            
_p("my","DELETE FROM ".$taula." WHERE id = ".$delete$_SESSION["conn_my"]); 
            
//echo "DELETE FROM ".$taula." WHERE id = ".$delete;
        
} else {
            
_p("pg","DELETE FROM ".$taula." WHERE id = ".$delete$_SESSION["conn_pg"]);
        }
    } 
?>                     

<TABLE CLASS="<? echo $class ?>" >

 <? // TITOLS TAULA 
    
for ($i=0$i<count($ws_); $i++) { ?>    
          <TH CLASS="TH1" WIDTH="<? echo $ws_[$i?>" ALIGN="CENTER"><A HREF="index.php?<? echo encrypt$ordres_[$i], $_SESSION["pwd"]) ?>" CLASS="<? echo $estil_href ?>"><? echo $titols_[$i]?></A></TH>
         <? 

    if (
$imatges != "") {
        
$i=0$j=0;
        while ( 
$j < (count($imatges_)/5) ) {   ?>
             <TH CLASS="TH1" WIDTH="<? echo $imatges_[$i+1?>"><? echo $imatges_[$i?></TH>
        <? $i=$i+5;
           
$j++;    
        } 
    } 

    if (
$tipus == "my") {

            
$rs mysql_query$sql $_SESSION["conn_my"]);
//echo $sql;
            // DADES TAULA  
            
while ($row mysql_fetch_row($rs)) { ?>                       
               
                          <TR HEIGHT="25" BGCOLOR="<? echo $color_[$k &#37; 2 ] ?>">
                    <? for ($i=0$i<count($ws_); $i++) {
                            if ( 
$url_link_[$i] == "" )  { ?>
                                <TD WIDTH="<? echo $ws_[$i?>" CLASS="TD1"><? echo $row[$i+1?></TD>
                            <? } else { 
                                    if (
substr($url_link_[$i],0,4) == "http") {?>            <!-- links sense encriptar -->
                                        <TD WIDTH="<? echo $ws_[$i?>" CLASS="TD1"><A HREF="<? echo $url_link_[$i].$row[$camp_link_[$i]] ?>" CLASS="<? echo $estil_href ?>"><? echo $row[$i+1?></A></TD>
                                <?  } else { ?>
                                        <TD WIDTH="<? echo $ws_[$i?>" CLASS="TD1"><A HREF="index.php?<? echo encrypt$url_link_[$i].$row[$camp_link_[$i]], $_SESSION["pwd"]) ?>" CLASS="<? echo $estil_href ?>"><? echo $row[$i+1?></A></TD>
                                <? }
                            }
                       } 
                       

                       if (
$imatges != "") {
                           
$i=0$j=0;
                           while ( 
$j < (count($imatges_)/5) ) {   
                                   if ( 
substr($imatges_[$i+3],0,1) != "\\" ) { ?>                                  
                                        <TD CLASS="TD1" ALIGN="CENTER"><A HREF="index.php?<? echo encrypt($imatges_[$i+3].$row[$imatges_[$i+4]], $_SESSION["pwd"]) ?>"><IMG SRC="<? echo $imatges_[$i+2?>" BORDER="0"></A>
                                   <? }                     
                           <? 
$i=$i+5;
                              
$j++; 
                           } 
                       }
?>
                          </TR>

        <?        $k++; 
            } 
    } else {  
//echo $sql;
            
$rs pg_exec$_SESSION["conn_pg"], $sql );

            
// DADES TAULA  
            
while ($row pg_fetch_row($rs)) {  ?>                       
               
                          <TR HEIGHT="25" BGCOLOR="<? echo $color_[$k ?>">
                    <? for ($i=0$i<count($ws_); $i++) {
                            if ( 
$url_link_[$i] == "" )  { ?>
                                <TD WIDTH="<? echo $ws_[$i?>" CLASS="TD1"><? echo $row[$i+1?></TD>
                            <? } else { ?>
                                <TD WIDTH="<? echo $ws_[$i?>" CLASS="TD1"><A HREF="index.php?<? echo encrypt$url_link_[$i].$row[$camp_link_[$i]], $_SESSION["pwd"]) ?>" CLASS="<? echo $estil_href ?>"><? echo $row[$i+1?></A></TD>    
                    <?        }
                       } 
                       

                       if (
$imatges != "") {
                           
$i=0$j=0;
                           while ( 
$j < (count($imatges_)/5) ) {   ?>
                                <TD CLASS="TD1" ALIGN="CENTER"><A HREF="<? echo $imatges_[$i+3].$row[$imatges_[$i+4]] ?>"><IMG SRC="<? echo $imatges_[$i+2?>" BORDER="0"></A>
                           <? $i=$i+5;
                              
$j++; 
                           } 
                       }
?>
                          </TR>

        <?        $k++; 
            } 
    }
?>

</TABLE>
<BR><BR>
<? 

$r 
GET2Arraydecryptsubstr($_SERVER["REQUEST_URI"],strpos($_SERVER["REQUEST_URI"],"?")+1,100), $_SESSION["pwd"]) );        //posa a l'array r els paràmetres GET (desencriptats)
$ordre $r[4];

//NÚMERO DE PÀGINES

if ($n_resultats 30) {

if (
$n_resultats 0) {
    
$post_FROM strpos($sql,"FROM")+5;
    
if (
$tipus == "my") {    
    
$pre_LIMIT strpos($sql,"LIMIT");
    
$sql_ "SELECT COUNT(*) FROM ".substr($sql$post_FROM$pre_LIMIT $post_FROM);        
    
$rs mysql_query$sql_$_SESSION["conn_my"]);

    
$i=0;
    
$pag=1;    

    echo 
"<A HREF='index.php?".encrypt("op=".$operacio."&offset=0&limit=".$n_resultats."&paraula=".$paraula."&ordre=".$ordre,$_SESSION["pwd"])."' CLASS='".$estil_href."'>|<</A>&nbsp;&nbsp;";

    while (
$i <= mysql_result($rs,0,0)) {
         
$estil_a $estil_href;
         if ( (
$pag-1) == ($r[1] / $n_resultats) )
               
$estil_a "pagina_actual";            //canviar l'estil per saber pàgina actua

         
echo "<A HREF='index.php?".encrypt("op=".$operacio."&offset=".(($pag-1)*$n_resultats)."&limit=".$n_resultats."&paraula=".$paraula."&ordre=".$ordre,$_SESSION["pwd"])."' CLASS='".$estil_a."'>".$pag."</A>&nbsp;&nbsp;";
           
$i=$i $n_resultats;
         
$pag++;
    }

    echo 
"<A HREF='index.php?".encrypt("op=".$operacio."&offset=".(($pag-2)*$n_resultats)."&limit=".$n_resultats."&paraula=".$paraula."&ordre=".$ordre,$_SESSION["pwd"])."' CLASS='".$estil_href."'>>|</A>&nbsp;&nbsp;";
    
} else {
    
$pre_OFFSET strpos($sql,"OFFSET");
    
$sql_ "SELECT * FROM ".substr($sql$post_FROM$pre_OFFSET $post_FROM);
    
$rs pg_exec($_SESSION["conn_pg"], $sql_);

    
$i=0;
    
$pag=1;    

    echo 
"<A HREF='index.php?".encrypt("op=".$operacio."&offset=0&limit=".$n_resultats."&paraula=".$paraula."&ordre=".$ordre,$_SESSION["pwd"])."' CLASS='".$estil_href."'>|<</A>&nbsp;&nbsp;";

    while (
$i <= pg_num_rows($rs) ) {
         
$estil_a $estil_href;
         if ( (
$pag-1) == ($r[1] / $n_resultats) )
               
$estil_a "pagina_actual";            //canviar l'estil per saber pàgina actual

         
echo "<A HREF='index.php?".encrypt("op=".$operacio."&offset=".(($pag-1)*$n_resultats)."&limit=".$n_resultats."&paraula=".$paraula."&ordre=".$ordre,$_SESSION["pwd"])."' CLASS='".$estil_a."'>".$pag."</A>&nbsp;&nbsp;";
           
$i=$i $n_resultats;
         
$pag++;
    }

    echo 
"<A HREF='index.php?".encrypt("op=".$operacio."&offset=".(($pag-2)*$n_resultats)."&limit=".$n_resultats."&paraula=".$paraula."&ordre=".$ordre,$_SESSION["pwd"])."' CLASS='".$estil_href."'>>|</A>&nbsp;&nbsp;";
}

}

}



?>