tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
4
ZUGRIFFE
281
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    D@nger Tutorials.de Gastzugang
    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-Code:

    <?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(1234567891011121314151617181920

    212223242526272829303132333435363738394041424344

    454647484950515253545556575859606162636465666768

    697071727374757677787980818283848586878889909192

    93949596979899100);








               
    while ((
    $data fgetcsv ($handle1000";") 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>"); 



    }




          
        
    ?>
     

  2. #2
    Avatar von Dennis Wronka
    Dennis Wronka Dennis Wronka ist offline Soulcollector
    Registriert seit
    Apr 2002
    Ort
    Hong Kong
    Beiträge
    12.296
    Blog-Einträge
    231
    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-Code:

    }


       }





    fclose ($handle); 


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




    Auch die vielen Leerzeilen im Code machen es nicht gerade einfacher den Ueberblick zu behalten.
     
    PHP Class Collection - PHP-Klassen fuer PHP 5 (und Teilweise auch fuer PHP 4)
    Updates: Catcher 1.1, FTPConnection 1.2, MultiSQL 1.1, RSS2 1.1, SMTPConnection 1.4
    __________________
    EasyLFS - Hintergrundinformationen, Installationsanleitung, Softwareliste und Download
    EasyLFS Projektthread - Informationen, Status und Diskussion zu meiner Linux-Distribution
    __________________
    Ich bin die Schildkroete, mein Sohn. Ich habe das Universum erschaffen, aber bitte mach mir daraus keinen Vorwurf; ich hatte Bauchschmerzen.
    __________________
    Zitat Zitat von Friedrich Nietzsche
    Man muss noch Chaos in sich haben, um einen tanzenden Stern gebaeren zu koennen.

  3. #3
    D@nger Tutorials.de Gastzugang
    Hallo, danke, das hilft zwar nicht bei meinem Problem...
    Gibt's ein Programm, was den Code automatisch formatiert?
     

  4. #4
    D@nger Tutorials.de Gastzugang
    Hallo, so, habe ein wirklich geniales Programm namens PSPAD gefunden, was den Code wie folgt formatiert hat:

    PHP-Code:
    <?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(123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100);
               
    while ((
    $data fgetcsv ($handle1000";") 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?
    Geändert von D@nger (28.08.06 um 15:35 Uhr)
     

  5. #5
    D@nger Tutorials.de Gastzugang
    So, jetzt sollte es stimmen

    PHP-Code:
    <?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(123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100);
               
          while ((
    $data fgetcsv ($handle1000";") 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>"); 

        }
          
    ?>
    Geändert von D@nger (28.08.06 um 16:15 Uhr)
     

Ähnliche Themen

  1. Compiler-Warnung wenn Variable nicht gesetzt wird
    Von XtremeCJ im Forum .NET Application und Service Design
    Antworten: 3
    Letzter Beitrag: 26.07.09, 16:01
  2. Antworten: 2
    Letzter Beitrag: 18.12.07, 10:39
  3. cookie wird nicht gesetzt
    Von DarkManX im Forum PHP
    Antworten: 11
    Letzter Beitrag: 26.07.05, 03:20
  4. Pruefen ob Variable gesetzt ist (=isset)
    Von rainerdam im Forum .NET Archiv
    Antworten: 6
    Letzter Beitrag: 05.10.04, 11:32
  5. chown wird nicht gesetzt :-/
    Von Friesi im Forum PHP
    Antworten: 3
    Letzter Beitrag: 16.05.04, 17:50