Comunidad de diseño web y desarrollo en internet online

Llenar datagrid con datos desde una bd usando php y mysql

Citar            
MensajeEscrito el 30 Dic 2005 11:55 pm
Hola a todos.
Deceo llenar un DataGrid con por lo menos 100 registros sacados de una bd usando php y mysql. El problema es como paso esos datos al datagrid. Alguien puede tirar un cable...?

Salu2

Por pulento

48 de clabLevel



 

msie
Citar            
MensajeEscrito el 31 Dic 2005 12:12 am
Ok.. he logrado meter datos en el Datagrid pero solo me muestra el primer registro y no los demas.
Este es el code del php

Código :

<?
mysql_connect("xxx","xxx","xxx") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
$query = mysql_query("SELECT * FROM bolig") or die(mysql_error());
$total_reg = mysql_num_rows($query);
while($row=mysql_fetch_array($query)){
$id                = $row['id'];
$statusLejlighed        = $row['statusLejlighed'];
$kvMeter             = $row['kvMeter'];
print "$total_reg&id=$id&statusLejlighed=$statusLejlighed&kvMeter=$kvMeter&";
}//while
?>



Y este es el code del flash

Código :

MovieClip.prototype.listerLejlighedsdata = function(){
var myLoadVars:LoadVars = new LoadVars();
myLoadVars.sendAndLoad("bolig.php", myLoadVars, "POST");
myLoadVars.onLoad = function(succes){
arrayId = new Array(100);
arrayStatus = new Array(100);
arrayKvMeter = new Array(100);
      if(succes){
            for(i=0;i<=70;i++){
               arrayId[i]     = this.id ; 
               arrayStatus[i] = this.statusLejlighed;
               arrayKvMeter[i]= this.kvMeter;
                mi_dg.addItem({ID:arrayId[i], Status: arrayStatus[i], Meter: arrayKvMeter[i]});
            }
      }//if
      else{
         _root.textFunciona.text = "FUCK . . !";
      }
   }//onLoad
}//listerLejlighedsdata


//Le ponemos un alto de celda igual a la imagen para que encajen bien
mi_dg.rowHeight = 25;mi_dg.resizableColumns = false;mi_dg.sortableColumns = false;
//Ponemos el ancho de las columnas
mi_dg.getColumnAt(0).width = 120;mi_dg.getColumnAt(1).width = 120;mi_dg.getColumnAt(2).width = 120;mi_dg.getColumnAt(3).width = 57;


Alguien puede ver el error..?

Salu2 y gracias

Por pulento

48 de clabLevel



 

msie
Citar            
MensajeEscrito el 31 Dic 2005 05:38 am
nota los cambios :wink:

Código :

<?
  mysql_connect("xxx","xxx","xxx") or die(mysql_error());
  mysql_select_db("xxx") or die(mysql_error());
  $query = mysql_query("SELECT * FROM bolig") or die(mysql_error());
  $total_reg = mysql_num_rows($query);
  $i=0;
  while($row=mysql_fetch_array($query)){
        $id = $row['id'];
      $statusLejlighed= $row['statusLejlighed'];
      $kvMeter= $row['kvMeter'];
      print "&id$i=$id&statusLejlighed$i=$statusLejlighed&kvMeter$i=$kvMeter&";
      $i++;
  }//while
?>


y en AS, solo cambia aqui:

Código :

arrayId[i]     = this["id"+i] ;
arrayStatus[i] = this["statusLejlighed"+i];
arrayKvMeter[i]= this["kvMeter"+i];


te explico, cuando usas loadVars debes construir las variables, sabrás que todas las variables deben tener nombres únicos, cosa que no estas haciendo con una variable &id=unvalorcualquiera, mi correcion le da un numero que las diferencia por un numero, &id0=unavalorcualquiera, &id1=unvalocualquiera1, &idN=unvalorcualquieraN, esto por el lado del php :wink: , ahora por el lado accederia por this["id"+elnumerocorrespondiente] :P

quizás mi código te pueda dar problemas, no lo probe, codifique aqui en el editor de respuesta :wink:

saludos :)

Por Maikel

BOFH

5575 de clabLevel

22 tutoriales
5 articulos

Genero:Masculino   Team Cristalab

Claber de baja indefinida

firefox
Citar            
MensajeEscrito el 01 Ene 2006 02:16 pm
Gracias por la ayuda Maikel, me ha sido de gran utilidad.

Salu2

Por pulento

48 de clabLevel



 

msie

 

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