Variable oder Array wird wieder auf 0 gesetzt

D

D@nger

Hallo,
an folgendem Code muss irgendetwas falsch sein, denn ich bekomme eine Tabelle, in der jede Zeile gleich ist, also es sind die gleichen Datensätze. Nehme ich die for-Schleife raus funktioniert es komischerweise. Also wird das Array wahrscheinlich wieder zurückgesetzt. Kann sich das vielleicht mal jemand anschauen? Vielen Dank schon mal.

PHP:
<?php 





  $sent = $_GET['sent'];
        
           $ausgeben = $_GET['ausgeben'];//Inhalt der Checkboxen

     
          if ($sent == 'yes') 
              {
                   $ausgeben_text = implode(', ',$ausgeben);
                 //  $ausgeben_array=explode(', ',$ausgeben_text);
     
                 
                   echo $ausgeben_text. "<br>";

// in $ausgeben_text steht 98, 99

                    
              





  $file = "CL_Artikelstamm.txt"; 
  $lines = file($file); 
  $numlines = count($lines);











print('<table border="1" cellpadding="10" cellspacing="0" style="border-collapse: collapse" 

bordercolor="#111111" height="128">'); 







$row = 1;                                      
$handle = fopen ("CL_Artikelstamm.txt","r");   


$id="1";
$i=0;
$d=0;


//while($id < $numlines && $id < 10) {














$ausgeben_array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 

21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 

45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 

69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 

93, 94, 95, 96, 97, 98, 99, 100);








           
while (($data = fgetcsv ($handle, 1000, ";") AND $id < $numlines AND $id < 

array_pop($ausgeben_array)+1) !== FALSE) { 










   $num = count ($data);  


  
$row++;    




     



    $Bezeichnung1 =  $data[2]; 
    $Bezeichnung2 = $data[3]; 
    $Preis = $data[7]; 
    $Bild = $data[8]; 



    //Get all field information out of the table 

    
    //Parse errors from the information (U 
    $Bezeichnung1 = str_replace("/n", "<br>", $Bezeichnung1); 
    $Bezeichnung2 = str_replace("/n", "<br>", $Bezeichnung2); 
   // $Preis = number_format($Preis, 2, ",", ""); 



// if ($i != 0)
 // {
 //  $d=$i+1;
//  }






  for ($i; $i < sizeof($ausgeben_array); $i++)
   {
    if (intval($ausgeben_array[$i]) == intval($id))
    {
    







  if($Bild=="") 
   { 
    $Bild="0"; 

    if (!file_exists("images/" . $Bild)) 
     { 
      $Bild="1"; 
     } 

   } 

     
    //We got all record information out! 
    //Example of usage: 






if ($id%2==0) 
{ 
print("<tr>"); 
} 
else 
{ 
print("<tr bgcolor=#CCCCCC>"); 
} 





//Spalten

 print("<td width=-6 height=44 valign=top><font face=Arial size=2>&nbsp;$id.<br><input 

type=checkbox value=$id name=ausgeben[] checked> </font></td>");

 print("<td width=108 height=44>"); 

 if ($Bild=="1") 
  { 
   print("&nbsp;<b><font face=Arial size=2>Kein Bild vorhanden</font></b>&nbsp;"); 
  } 
  else 
  { 
   print("<img src=images/$Bild width=150>"); 
  } 

 print("</td>"); 

 print("<td width=200 height=44 valign=top><b><font face=Arial size=2>$Bezeichnung1</b>
 <br>
 Best.Nr.:   
 <br>
 $Bezeichnung2
 <br>
 <br>
 <b>Preis: $Preis EUR</b>

</font>

</td>");
   

if($id=="1") 
     { 
     $id="2"; 
     }   
else 
{ 
$id=$id+1; 
} 



 

//}


} 
}


   }





fclose ($handle); 


      print("</tr></table>"); 



}




      
    ?>
 
Also ich find den Code in der Form praktisch unlesbar, man kann ja garnicht sehen wo die For-Schleife wieder aufhoert.
Daher moechte ich Dich doch, auch in Deinem Interesse, bitten die Formatierung des Codes ein wenig klarer zu gestalten und nicht solche abenteuerlichen Konstrukte wie das folgende zu bieten:
PHP:
} 
}


   }





fclose ($handle); 


      print("</tr></table>"); 



}
Auch die vielen Leerzeilen im Code machen es nicht gerade einfacher den Ueberblick zu behalten.
 
Hallo, danke, das hilft zwar nicht bei meinem Problem...
Gibt's ein Programm, was den Code automatisch formatiert?
 
Hallo, so, habe ein wirklich geniales Programm namens PSPAD gefunden, was den Code wie folgt formatiert hat:

PHP:
<?php 
  $sent = $_GET['sent'];
        
           $ausgeben = $_GET['ausgeben'];//Inhalt der Checkboxen
     
          if ($sent == 'yes') 
              {
                   $ausgeben_text = implode(', ',$ausgeben);
                 //  $ausgeben_array=explode(', ',$ausgeben_text);
     
                 
                   echo $ausgeben_text. "<br>";
// in $ausgeben_text steht 98, 99
                    
              
  $file = "CL_Artikelstamm.txt"; 
  $lines = file($file); 
  $numlines = count($lines);
print('<table border="1" cellpadding="10" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" height="128">'); 
$row = 1;                                      
$handle = fopen ("CL_Artikelstamm.txt","r");   
$id="1";
$i=0;
$d=0;
//while($id < $numlines && $id < 10) {
$ausgeben_array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100);
           
while (($data = fgetcsv ($handle, 1000, ";") AND $id < $numlines AND $id < array_pop($ausgeben_array)+1) !== FALSE) { 
   $num = count ($data);  
  
$row++;    
     
    $Bezeichnung1 =  $data[2]; 
    $Bezeichnung2 = $data[3]; 
    $Preis = $data[7]; 
    $Bild = $data[8]; 
    //Get all field information out of the table 
    
    //Parse errors from the information (U 
    $Bezeichnung1 = str_replace("/n", "<br>", $Bezeichnung1); 
    $Bezeichnung2 = str_replace("/n", "<br>", $Bezeichnung2); 
   // $Preis = number_format($Preis, 2, ",", ""); 
// if ($i != 0)
 // {
 //  $d=$i+1;
//  }
  for ($i; $i < sizeof($ausgeben_array); $i++)
   {
    if (intval($ausgeben_array[$i]) == intval($id))
    {
    
  if($Bild=="") 
   { 
    $Bild="0"; 
    if (!file_exists("http://www.tutorials.de/forum/images/" . $Bild)) 
     { 
      $Bild="1"; 
     } 
   } 
     
    //We got all record information out! 
    //Example of usage: 
if ($id%2==0) 
{ 
print("<tr>"); 
} 
else 
{ 
print("<tr bgcolor=#CCCCCC>"); 
} 
//Spalten
 print("<td width=-6 height=44 valign=top><font face=Arial size=2>&nbsp;$id.<br><input type=checkbox value=$id name=ausgeben[] checked> </font></td>");
 print("<td width=108 height=44>"); 
 if ($Bild=="1") 
  { 
   print("&nbsp;<b><font face=Arial size=2>Kein Bild vorhanden</font></b>&nbsp;"); 
  } 
  else 
  { 
   print("<img src=images/$Bild width=150>"); 
  } 
 print("</td>"); 
 print("<td width=200 height=44 valign=top><b><font face=Arial size=2>$Bezeichnung1</b>
 <br>
 Best.Nr.:   
 <br>
 $Bezeichnung2
 <br>
 <br>
 <b>Preis: $Preis EUR</b>
</font>
</td>");
   
if($id=="1") 
     { 
     $id="2"; 
     }   
else 
{ 
$id=$id+1; 
} 
 
//}
} 
}
   }
fclose ($handle); 
      print("</tr></table>"); 
}
      
?>

Mir fällt aber gerade auf, dass das doch nicht so ganz stimmt. Ich korrigiere noch mal.

Kommt ihr damit weiter?
 
Zuletzt bearbeitet von einem Moderator:
So, jetzt sollte es stimmen ;-)

PHP:
<?php 

  $sent = $_GET['sent'];
  $ausgeben = $_GET['ausgeben'];//Inhalt der Checkboxen
     
  if ($sent == 'yes') 
    {
      $ausgeben_text = implode(', ',$ausgeben);
      //  $ausgeben_array=explode(', ',$ausgeben_text);
      echo $ausgeben_text. "<br>";
      // in $ausgeben_text steht 98, 99
                    
              
      $file = "CL_Artikelstamm.txt"; 
      $lines = file($file); 
      $numlines = count($lines);
  
      print('<table border="1" cellpadding="10" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" height="128">'); 
      $row = 1;                                      
      $handle = fopen ("CL_Artikelstamm.txt","r");   
      $id="1";
      $i=0;
      $d=0;
  
      //while($id < $numlines && $id < 10) {
      $ausgeben_array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100);
           
      while (($data = fgetcsv ($handle, 1000, ";") AND $id < $numlines AND $id < array_pop($ausgeben_array)+1) !== FALSE)
        { 
          $num = count ($data);  
          $row++;    

          $Bezeichnung1 =  $data[2]; 
          $Bezeichnung2 = $data[3]; 
          $Preis = $data[7]; 
          $Bild = $data[8]; 
          //Get all field information out of the table 
    
          //Parse errors from the information (U 
          $Bezeichnung1 = str_replace("/n", "<br>", $Bezeichnung1); 
          $Bezeichnung2 = str_replace("/n", "<br>", $Bezeichnung2); 
          // $Preis = number_format($Preis, 2, ",", ""); 
      
          // if ($i != 0)
          // {
          //  $d=$i+1;
          //  }
      
          for ($i; $i < sizeof($ausgeben_array); $i++)
            {
              if (intval($ausgeben_array[$i]) == intval($id))
                {
    
                  if($Bild=="") 
                    { 
                      $Bild="0"; 
                  
                      if (!file_exists("images/" . $Bild)) 
                        { 
                          $Bild="1"; 
                        } 
                    } 
     
                  if ($id%2==0) 
                    { 
                      print("<tr>"); 
                    } 
                      else 
                        { 
                           print("<tr bgcolor=#CCCCCC>"); 
                        } 

                  //Spalten
                  print("<td width=-6 height=44 valign=top><font face=Arial size=2>&nbsp;$id.<br><input type=checkbox value=$id name=ausgeben[] checked> </font></td>");
                  print("<td width=108 height=44>"); 
                  if ($Bild=="1") 
                    { 
                      print("&nbsp;<b><font face=Arial size=2>Kein Bild vorhanden</font></b>&nbsp;"); 
                    } 
                      else 
                        { 
                           print("<img src=images/$Bild width=150>"); 
                        } 
                  print("</td>"); 
                  print("<td width=200 height=44 valign=top><b><font face=Arial size=2>$Bezeichnung1</b>
                  <br>
                  Best.Nr.:   
                  <br>
                  $Bezeichnung2
                  <br>
                  <br>
                  <b>Preis: $Preis EUR</b>
                  </font>
                  </td>");
   
                  if($id=="1") 
                    { 
                      $id="2"; 
                    }   
                      else 
                        { 
                          $id=$id+1; 
                        } 
 

                } 
            }
        }
    
      fclose ($handle); 
      print("</tr></table>"); 

    }
      
?>
 
Zuletzt bearbeitet von einem Moderator:

Neue Beiträge

Zurück