We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32982
    • 674 Posts
    im going cracy i couldent work a code like this for return a droplist whith selected items from a array.
    could anyone help me?
    <select onChange="documentDirty=true;" name="tallas[]" size="4" multiple id="tallas[]">
    <?php

    for ($i = 15; $i <= 45; $i++) {
    $a= array(16,17);
    if($i =$a ){
    echo "<option value=’$i’selected>$i</option> ";}
    else{echo "<option value=’$i’>$i</option> ";}
    }?>

    </select>
    thanks
      Jabiertxof (formerly XYZVISUAL)
      My bussines: http://marker.es
      https://www.youtube.com/user/jabiertxof/videos
      • 18397
      • 3,250 Posts
      Found your problem!

      $i can’t equal an array. It must equal a specific record in an array.
      $a[n] where n is the record.
        • 31337
        • 258 Posts
        You probably mean:

        $i == $a[0]


        Right? You have to: 1) Subscript into the array and 2) Use ’==’ for comparision instead of ’=’ (which is used for assignment).
          • 32982
          • 674 Posts
          thanks for the help i solve it whith this code
          <select onChange="documentDirty=true;" name="tallas[]" size="4" multiple id="tallas[]">
          <?php

          for ($i = 15; $i <= 45; $i++) {
          $a= array(16,17);
          if($i==$a[0]or$i==$a[1]or$i==$a[2]){
          echo "<option value=’$i’selected>$i</option> ";}
          else{echo "<option value=’$i’>$i</option> ";}
          }?>

          </select>
            Jabiertxof (formerly XYZVISUAL)
            My bussines: http://marker.es
            https://www.youtube.com/user/jabiertxof/videos