Frage zu Variablenproblem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • druckgott
    replied
    es dividiert den wert $i durch 2 und schaut ob es 0 ist

    hab es geschaft danke:

    PHP Code:
    <?php
    //befüllen wir mal einen Array
    $kom[]="test";
    $kom[]="fdsa";
    $kom[]="gghhg";

    $i 0;


    foreach(
    glob('./voksfestfliegen20061908_loisl_sepp*.jpg') as $key  => $file)

    echo 
    $i;
     if (
    $i == 0
    {
    echo 
    "<table width='100%' border='0'>";      
        echo 
    "
        <tr>
            <td><img src='
    $file' border='0'></td>
            <td width='100'>Bild Nr. 
    $key</td>
            <td width='50%'><div align='center'>"
    .$kom[$key]."</div></td>
        </tr>"
    ;
        echo 
    "</table>";
        
    $i=$i+1;
        }
        else 
        {
        echo 
    "<table width='100%' border='0'>";      
        echo 
    "
        <tr>
            <td width='50%'><div align='center'>"
    .$kom[$key]."</div></td>
            <td width='100'>Bild Nr. 
    $key</td>
            <td><div align='right'><img src='
    $file' border='0'></div></td>
        </tr>"
    ;
        echo 
    "</table>";
        
    $i=$i-1;
        }
        }
    ?>
    Last edited by druckgott; 02-12-2006, 11:39.

    Leave a comment:


  • penizillin
    replied
    PHP Code:
    $i 0;
    foreach(
    $arr as $k => $v)
    {
        echo 
    $i;
        if(
    $i == 0)
            echo 
    ' ist gerade<br />';
        else
            echo 
    ' ist ungerade<br />';

        
    $i++;

    soweit klar?

    kontrollfrage: was ist "%" und was macht es in diesem fall?

    Leave a comment:


  • druckgott
    replied
    So jetzt hab ich noch eine Frage. Ich hab das Script jetzt ausgebaut bzw. bin dabei.

    PHP Code:
    <?php
    //befüllen wir mal einen Array
    $kom[]="test";
    $kom[]="fdsa";
    $kom[]="gghhg";

    foreach(
    glob('./voksfestfliegen20061908_loisl_sepp*.jpg') as $key  => $file)


     if (
    $key == $ungearde
    {
    echo 
    "<table width='100%' border='0'>";      
        echo 
    "
        <tr>
            <td><img src='
    $file' border='0'></td>
            <td width='100'>Bild Nr. 
    $key</td>
            <td width='50%'><div align='center'>"
    .$kom[$key]."</div></td>
        </tr>"
    ;
        echo 
    "</table>";
        }
        else 
        {
        echo 
    "<table width='100%' border='0'>";      
        echo 
    "
        <tr>
            <td width='50%'><div align='center'>"
    .$kom[$key]."</div></td>
            <td width='100'>Bild Nr. 
    $key</td>
            <td><div align='right'><img src='
    $file' border='0'></div></td>
        </tr>"
    ;
        echo 
    "</table>";
        }
        }
    ?>
    Er soll jetzt jedes zweite Bild links setzten. Deswegen will ich, dass wenn bei der if anwendung $i == "einer ungeraden Zahl ist" er das erste macht sonst das zweite.
    Leider hab ich das jetzt vergeblich versucht. Habe es mit einer while schleife versucht aber bekomme das nicht gebacken, da ich nicht weiß wie ich gleichzeitig zu jedem Bild eine zahl hochzählen kann, weil wenn ich das so machen:
    PHP Code:
    foreach(glob('./voksfestfliegen20061908_loisl_sepp*.jpg') as $key  => $file && $i=0;$i<=count($key);$i=$i+0.5
    haut das ja nicht hin.
    Gibt es vielleicht ein zeichen, dass das nur bei ungeraden Zahlen erfüllt ist?

    vielleicht kann mir jemand eine kleine Hilfe leisten
    Last edited by druckgott; 02-12-2006, 10:05.

    Leave a comment:


  • druckgott
    replied
    ah super danke jetzt haut es hin

    Leave a comment:


  • jahlives
    replied
    PHP Code:
    <?php
    //befüllen wir mal einen Array
    $kom[]="test";
    $kom[]="fdsa";
    $kom[]="gghhg";
    echo 
    "<table width='180' border='0'>";
    foreach(
    glob('./voksfestfliegen20061908_loisl_sepp*.jpg') as $key  => $file){        
        echo 
    "
        <tr>
            <td><img src='
    $file' border='0'></td>
            <td>Bild Nr. 
    $key</td>
            <td>"
    .$kom[$key]."</td>
        </tr>"
    ;
        echo 
    "</table>";
    }
    ?>
    So in der Art etwa.

    Gruss

    tobi
    Last edited by jahlives; 01-12-2006, 20:14.

    Leave a comment:


  • TobiaZ
    replied
    na, arrays sind wohl wirklich grundlagen und sogar einfacher als variable variablen.

    Leave a comment:


  • druckgott
    replied
    mhh das probelm ist soviel ahnung hab ich eben nicht hab schon ewig gebraucht das überhaupt hinzubekommen das er mir die zahlen dazu auflistet.

    Leave a comment:


  • wahsaga
    replied
    Nutze Arrays, alles andere ist Blödsinn.

    Und auch glob solltest du nicht in der Schleifenbedingung machen, sondern vorher - Ergebnis in einen weiteren Array ablegen, und über dieses eine Schleife laufen lassen.

    Leave a comment:


  • TobiaZ
    replied
    stichwort variable variablen oder nimm gleich arrays.

    Leave a comment:


  • jahlives
    replied
    Sag mir erstmal was genau du machen willst. Du verknüpfst den String kom einfach mit einer Zahl

    Gruss

    tobi

    Leave a comment:


  • druckgott
    replied
    hä das heißt das geht nicht oder wie?
    also ich meine wie ich das machen will!

    Leave a comment:


  • jahlives
    replied
    Allerdings zeigt er mir hinter den Bildern nicht die $kom0 usw. an, sondern er zeigt mir "kom0" usw. an.
    Works as designed... Der Key ist die Array Position des Elementes. Also wird daraus logischerweise ein 'kom'+zahl

    Leave a comment:


  • druckgott
    started a topic Frage zu Variablenproblem

    Frage zu Variablenproblem

    Hallo ich habe eine Frage:
    Das ist mein Script:

    PHP Code:
    <?php
    $kom0
    ="test";
    $kom1="fdsa";
    $kom2="gghhg";

    echo 
    "<table width='180' border='0'>";
    foreach(
    glob('./voksfestfliegen20061908_loisl_sepp*.jpg') as $key  => $file)        
        echo 
    "
        <tr>
            <td><img src='
    $file' border='0'></td>
            <td>Bild Nr. 
    $key</td>
            <td>kom"
    .$key."</td>
        </tr>"
    ;
        echo 
    "</table>";
    ?>
    Allerdings zeigt er mir hinter den Bildern nicht die $kom0 usw. an, sondern er zeigt mir "kom0" usw. an.
    An was liegt das?

    Und dann hätte ich noch eine Frage. Wie kann ich das verwirklichen, dass ich immer ein Bild rechts und das nächste links und dann wieder rechts angezeigt bekomme?

    bitte um hilfe bin php Neuling
    Last edited by druckgott; 01-12-2006, 18:43.
Working...
X