php - Why can't I have duplicate working functions? -


i have config page creating in php, have used code found create dropdown files found in folder

 <?php   $folder = '../pic/upload';   echo '<select name="sabpic">'."\n".       dropdown(image_filenames($folder), @$_post['image']).       '</select>'."\n".'</br></br>';   function image_filenames($dir)  {      $handle = @opendir($dir)          or die("i cannot open directory '<b>$dir</b>' reading.");      $images = array();      while (false !== ($file = readdir($handle)))      {          if (eregi('\.(jpg|gif|png)$', $file))          {              $images[] = $file;          }      }      closedir($handle);      return $images;  }   function dropdown($options_array, $selected = null)  {  global $sabpicname;     $return = null;      foreach($options_array $option)      {          $return .= '<option value="'.$option.'"'.                     (($option == $sabpicname) ? ' selected="selected"' : null ).                     '>'.$option.'</option>'."\n";      }      return $return;  }   ?> 

now works "selecting picture sab" , when page loaded reads value in $sabpicname , selects option default expected.

i assumed take same function , modify $sabpicname $sickpicname , work same select value contained in variable instead..

<?php   echo '<select name="sickpic">'."\n".       dropdown(image_filenames($folder), @$_post['image2']).       '</select>'."\n".'</br></br>';   function dropdown_sick($options_array, $selected = null)  {  global $sickpicname;     $return2 = null;      foreach($options_array $option2)      {          $return2 .= '<option value="'.$option2.'"'.                     (($option2 == $sickpicname) ? ' selected="selected"' : null ).                     '>'.$option2.'</option>'."\n";      }      return $return2;  }   ?> 

but no matter seem do, second dropdown still taking selected value stored in $sabpicname , not $sickpicname, can see, seperate function , doesn't reference $sabpicname variable atall, it's not working, i'm missing something..

hope can shine light on im doing wrong.

stupid me, can see still calling orignal dropdown, knew had stupid..

<?php   echo '<select name="sickpic">'."\n".       dropdown_sick(image_filenames($folder), @$_post['image2']).       '</select>'."\n".'</br></br>';   function dropdown_sick($options_array, $selected = null)  {  global $sickpicname;     $return2 = null;      foreach($options_array $option2)      {          $return2 .= '<option value="'.$option2.'"'.                     (($option2 == $sickpicname) ? ' selected="selected"' : null ).                     '>'.$option2.'</option>'."\n";      }      return $return2;  }   ?> 

thank ryan


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -