smordue Posted December 28, 2009 Share Posted December 28, 2009 I am using the following code, which you guys helped me with last week. <?php $cur_group = ''; $files = scandir('images/siteimgs'); sort($files); $thelist .= '<option selected="selected"'; $thelist .= '>Select Site Image</option>'; foreach($files as $file) { if ($file == '.' || $file == '..') { continue; } $file_x = substr($file, 0, -4); $file_y = explode("-", $file_x); $group = substr($file, 0, strpos($file, '-')); if(empty($cur_group)) { $thelist .= '<optgroup label="'.$group.'">'; $cur_group = $group; } if($group != $cur_group) { $thelist .= '</optgroup>'; $thelist .= '<optgroup label="'.$group.'">'; $cur_group = $group; } $thelist .= '<option value="picture-switcher.php?picture='.$file_x.'">'.$file_y[1].'</option>'; } ?><select onchange="window.location.href=this.options[this.selectedIndex].value"> <?php echo $thelist; ?> </select> It is working great, but I have a new need and that is to on another page, filter the results to only show images with a certain prefix. My images are like so: Finance-Money.jpg Legal-Gavel.jpg etc. I would like to add something to the above code so that it only shows the images that start with "Legal-" for example. Thanks for your help, I could not do this without you guys! Steve Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 28, 2009 Share Posted December 28, 2009 <?php $cur_group = ''; $files = scandir('images/siteimgs'); sort($files); $thelist .= '<option selected="selected"'; $thelist .= '>Select Site Image</option>'; $filter = 'WHATEVER YOUR LOOKING FOR' foreach($files as $file) { if ($file == '.' || $file == '..' || strpos($file,$filter) === false) { continue; } $file_x = substr($file, 0, -4); $file_y = explode("-", $file_x); $group = substr($file, 0, strpos($file, '-')); if(empty($cur_group)) { $thelist .= '<optgroup label="'.$group.'">'; $cur_group = $group; } if($group != $cur_group) { $thelist .= '</optgroup>'; $thelist .= '<optgroup label="'.$group.'">'; $cur_group = $group; } $thelist .= '<option value="picture-switcher.php?picture='.$file_x.'">'.$file_y[1].'</option>'; } ?><select onchange="window.location.href=this.options[this.selectedIndex].value"> <?php echo $thelist; ?> </select> Quote Link to comment Share on other sites More sharing options...
smordue Posted December 28, 2009 Author Share Posted December 28, 2009 Awesome, thanks buddski Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.