Foros del Web » Programando para Internet » PHP »

problema-->Cannot use a scalar value as an array

Estas en el tema de problema-->Cannot use a scalar value as an array en el foro de PHP en Foros del Web. Buenas compañeros! :) estoy haciendo unas graficas, que se coonstruyen dependiendo del nº de resultados, va a tener mas linias o menos.. lo que hago ...
  #1 (permalink)  
Antiguo 07/06/2009, 08:26
 
Fecha de Ingreso: abril-2008
Mensajes: 144
Antigüedad: 16 años, 1 mes
Puntos: 1
Pregunta problema-->Cannot use a scalar value as an array

Buenas compañeros! :)
estoy haciendo unas graficas, que se coonstruyen dependiendo del nº de resultados, va a tener mas linias o menos.. lo que hago és dibujar el gràfico, los datos de cada grafico los guardo asi:

Código PHP:
$i=0;
 while(
$row=mysql_fetch_array($result))     // Extreu la fila resultant com una matriu associativa (clau,valor)
                                
{
                                    if (
$i==0)
                                    
$ydataa[]= $row["milk"];
                                    if (
$i==1)
                                    
$ydatab[]= $row["milk"];
                                    if (
$i==2)
                                    
$ydatac[]= $row["milk"];
                                    if (
$i==3)
                                    
$ydatad[]= $row["milk"];
                                    if (
$i==4)
                                    
$ydatae[]= $row["milk"];
                                    if (
$i==5)
                                    
$ydataf[]= $row["milk"];
                                                                       
$i=$i+1;
                                    
                                } 

el problema de hacerlo con a,b c,d etc.. es porque no puedo usar esto:$ydata.$i[]= $row["milk"]; porque me sale el mensaje del titulo ..Cannot use a scalar value as an array

Código PHP:
i=0;
 while(
$row=mysql_fetch_array($result))     // Extreu la fila resultant com una matriu associativa (clau,valor)
                                
{
                                    
                                    
$ydata.$i[]= $row["milk"];
                                    
                                    
$i=$i+1;
                                } 
de que forma lo puedo hacer?? OS dejo el codigo completo :)



Código PHP:
[LEFT]

   
$i=0;
                    
reset($resultwhile);//ens posem el principi.
                    
while(list($a$b) = each($resultwhile)) 
                    {
                                
//echo "_________ $a ==>________ $b\n"; $b=id_lac
                                    
                                
$sql " SELECT h.herd_id, h.codi, p.milk,p.scc
                                  FROM production p, herd h
                                  WHERE h.codi = '$codivaca'
                                  and p.fk_milklac_id = '$b'
                                  AND h.herd_id = p.herd_id
                                  GROUP BY p.testdate
                                  "
;
                                
//echo $sql;
                                
$consultsql=new Consultabd($localhost,$userbd,'',$_SESSION['bd']);
                                
$result=$consultsql->executar($sql);
                            
                               
                               while(
$row=mysql_fetch_array($result))     // Extreu la fila resultant com una matriu associativa (clau,valor)
                                
{
                                    if (
$i==0)
                                    
$ydata1[]= $row["milk"];
                                    if (
$i==1)
                                    
$ydatab[]= $row["milk"];
                                    if (
$i==2)
                                    
$ydatac[]= $row["milk"];
                                    if (
$i==3)
                                    
$ydatad[]= $row["milk"];
                                    if (
$i==4)
                                    
$ydatae[]= $row["milk"];
                                    if (
$i==5)
                                    
$ydataf[]= $row["milk"];
                                    
                                }
                                
                                
                                
$i=$i+1;
                                
                    }
                        
                        
                         
// Quan ja tenim les dades guardades per crear el gràfic, creem un nou gràfic de 300x200
               
                      
$graphllet = new Graph(300200"auto");   //mides del grafic
                      
$graphllet->SetScale"textlin");
                      
$graphllet->img->SetMargin(35,55,35,40); //(margeesquerra,margedret,margesuperior,margeinferior
                      
                       //titols
                        
$graphllet->title->Set$titol1" Num: ".$codivaca" Any "$anydades);
                        
$graphllet->xaxis->title->Set('Mesos');
                        
$graphllet->yaxis->title->Set($titol1); //eixy
                        // Get localised version of the month names
                        
$graphllet->xaxis->SetTickLabels($gDateLocale->GetShortMonth());
                                                
                        
                        if(isset (
$ydata1))
                        {        
                        
$lineplot1 = new lineplot($ydata1);
                        
$lineplot1->SetColor("blue");  //tipus grafic és la variable que guarda lineplot o barplot.
                        
$lineplot1->SetLegend('ydata1');
                         
$graphllet->Add($lineplot1);
                        }
                        if(isset (
$ydatab))
                        {        
                        
$lineplot2 = new lineplot($ydatab);
                        
$lineplot2->SetColor("red");  //tipus grafic és la variable que guarda lineplot o barplot.
                        
$lineplot2->SetLegend('ydatab');
                         
$graphllet->Add($lineplot2);
                        }
                        if(isset (
$ydatac))
                        {        
                        
$lineplot3 = new lineplot($ydatac);
                        
$lineplot3->SetColor("black");  //tipus grafic és la variable que guarda lineplot o barplot.
                        
$lineplot3->SetLegend('ydatac');
                         
$graphllet->Add($lineplot3);
                        }
                        if(isset (
$ydatad))
                        {        
                        
$lineplot4 = new lineplot($ydatad);
                        
$lineplot4->SetColor("green");  //tipus grafic és la variable que guarda lineplot o barplot.
                        
$lineplot4->SetLegend('ydatad');
                        
$graphllet->Add($lineplot4);
                        }
                        
                        
// Augmentemm el marge del grafic per posar la llegenda
                        
$graphllet->title->SetMargin(3);
                        
$graphllet->title->SetFont(FF_COMIC,FS_NORMAL,12);
                        
// llegenda
                        // Adjust the position of the legend box
                         
$graphllet->legend->Pos(0.03,0.10);
                         
$graphllet->Stroke("graficllet.png");[/LEFT
gracias
  #2 (permalink)  
Antiguo 07/06/2009, 09:24
 
Fecha de Ingreso: junio-2009
Ubicación: Mar del Plata
Mensajes: 33
Antigüedad: 14 años, 10 meses
Puntos: 1
Respuesta: problema-->Cannot use a scalar value as an array

Me parece que lo que quieres hacer es esto:

Código PHP:
$i=0;
while(
$row=mysql_fetch_array($result)) 
             {
                  
$ydataf[$i]= $row["milk"];
                  
$i=$i+1;
             } 
  #3 (permalink)  
Antiguo 07/06/2009, 15:26
 
Fecha de Ingreso: abril-2008
Mensajes: 144
Antigüedad: 16 años, 1 mes
Puntos: 1
De acuerdo Respuesta: problema-->Cannot use a scalar value as an array

Cita:
Iniciado por RodrigoQ Ver Mensaje
Me parece que lo que quieres hacer es esto:

Código PHP:
$i=0;
while(
$row=mysql_fetch_array($result)) 
             {
                  
$ydataf[$i]= $row["milk"];
                  
$i=$i+1;
             } 
Buenas Rodrigo :) y gracias... esto ya lo habia provado, y para crear el grafico me salia error, de todas dormas me has dado una idea y ahora si ya funciona :)

asi...
Código PHP:
$i=0;
while(
$row=mysql_fetch_array($result)) 
             {
                  
$ydataf[$i][]= $row["milk"];
                  
$i=$i+1;
             } 
graciasssssss :P
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:07.