Comunidad de diseño web y desarrollo en internet online

referirse a una tabla PHP>mySQL

Citar            
MensajeEscrito el 17 Jul 2006 12:02 am
En una clase de php para remoting, ¿como hago para que un parámetro que le paso sea el nombre de una tabla?

Código :

function init($table,$maxItems){
         //$maxItem=&$maxItems;
         $sql="SELECT name,points,date FROM /*******¿qué pongo aquí? *******/ORDER BY  points DESC LIMIT ".$maxItems."";
         return $this->query($sql,0);
      }

Esto en AS sería algo como myDB["table"].

Por Zah

BOFH

4290 de clabLevel

27 tutoriales
5 articulos

  Bastard Operators From Hell Editores

Zaragoza, España

firefox
Citar            
MensajeEscrito el 17 Jul 2006 01:46 am
si lo haces con maxItems, por que no con table?

Código :

function init($table,$maxItems){

         //$maxItem=&$maxItems;

         $sql="SELECT name,points,date FROM $table ORDER BY  points DESC LIMIT ".$maxItems."";

         return $this->query($sql,0);

      }


saludos

Por Maikel

BOFH

5575 de clabLevel

22 tutoriales
5 articulos

Genero:Masculino   Team Cristalab

Claber de baja indefinida

firefox
Citar            
MensajeEscrito el 17 Jul 2006 11:59 am
Es lo primero que probé, pero así no funciona, supongo que porque no puede entender los Strings como nombres de tabla...
Pongo todo el código por si acaso (una burda copia de tu tutorial XD)

Código :

<?php
   class Records{
      var $maxItem;
      function Records(){
      $this->maxItem=5;
         $this->methodTable = array(
            "init" => array(
               "description"=>"pasa las variables iniciales y devuelve toda la tabla",
               "access"=>"remote",
               "arguments"=>array("table","maxItems")
            ),
            "add" => array (
               "description"=>"añade una puntuacion",
               "access"=>"remote",
               "arguments"=>array("nombre","puntos")
            ),
            "show" => array (
               "description"=>"muestra las primeras n puntuaciones",
               "access"=>"remote",
               "arguments"=>array("n")
            ),
            "query"=>array(
               "description"=>"ejecuta un query a MYSQL",
               "access"=>"private",
               "arguments"=>array("sql","accion")
            ),
         );
      }
      function init($table,$maxItems){
         //$maxItem=&$maxItems;
         $sql="SELECT name,points,date FROM $table ORDER BY  points DESC LIMIT ".$maxItems."";
         $this->maxItem=45;
         return $this->query($sql,0);
      }
      function add ($nombre,$puntos){
         $nombre= utf8_encode($nombre);
         $fecha= utf8_encode($fecha);
         $sql="INSERT INTO game1 (id,name,points,date) VALUES ('','".$nombre."','".$puntos."',NOW())";
         //return  $this->query($sql,1);
         return $this->maxItem;
      }
      function show ($n){
         $sql="SELECT name,points,date FROM game1 ORDER BY  points DESC LIMIT ".$n."";
         return $this->query($sql,0);
      }
      function query($sql,$accion){
         $conex=mysql_connect("localhost","root") or die ("no se puede conectar: ".mysql_error());
         mysql_select_db("recordsdb");
         $result=mysql_query($sql,$conex);
         if($accion && result){
            $result=mysql_insert_id();
         }
         mysql_close($conex);
         return $result;
      }
      
   }
?>

Y en AS:

Código :

import mx.remoting.NetServices;
import mx.remoting.Connection;
mx.remoting.debug.NetDebug.initialize();
NetServices.setDefaultGatewayUrl("http://localhost/remoting/gateway.php");
conexion = NetServices.createGatewayConnection();
capturaRespuesta = new Object();
servicio = conexion.getService("Records", capturaRespuesta);
capturaRespuesta.onStatus = function(data) {
   trace("Fuck un error, por:"+data.description);
};
capturaRespuesta.init_Result = function(data) {
   a = 50;
   var proveedor:Array = new Array();
   if (data) {
      if (data.getLength()) {
         //trace(data.getLength());
         for (i=0; i<data.getLength(); i++) {
            proveedor.addItem({nombre:unescape(data.getItemAt(i).name), puntuacion:data.getItemAt(i).points, fecha:unescape(data.getItemAt(i).date)});
         }
         datagrid.dataProvider = proveedor;
         //trace(datagrid.dataProvider);
         datagrid.getColumnAt(0).widatah = 100;
         datagrid.getColumnAt(1).widatah = 50;
         datagrid.getColumnAt(2).widatah = 75;
         datagrid.selectedIndex = 0;
      }
   }
};
capturaRespuesta.add_Result = function(data) {
   trace(a);
   trace(data);
};
bt.onRelease = function() {
   servicio.add("zah", random(200));
   servicio.init("game1", 10);
};
//servicio.show(1);
servicio.init("game1", 10);

Por Zah

BOFH

4290 de clabLevel

27 tutoriales
5 articulos

  Bastard Operators From Hell Editores

Zaragoza, España

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.