homepage Welcome to WebmasterWorld Guest from 54.198.148.191
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
remove a select option from loop if equals
ahmed24




msg:3989668
 12:21 pm on Sep 15, 2009 (gmt 0)

hi,

i have a loop which displays select options like this:

foreach($codes as $key => $val){
echo "<option value='CODE_".$codes[$key]['ID']."'>".$codes[$key]['TITLE']."</option>";
}

I also have a variable called $remove

I would like to know how i can skip a loop in my code if the $codes[$key]['TITLE'] value matches the $remove variable value ?

any ideas?

thanks

[edited by: ahmed24 at 12:50 pm (utc) on Sep. 15, 2009]

 

ahmed24




msg:3989671
 12:50 pm on Sep 15, 2009 (gmt 0)

i think i have figured it out, the following way seems to work:

if ($codes[$key]['TITLE'] == $remove) continue;

can anyone confirm if this is the correct way?

thanks

BungeeJumper




msg:3989673
 12:54 pm on Sep 15, 2009 (gmt 0)

echo everything that is not equal - the equal one(s) won't be echoed 'not equal
foreach($codes as $key => $val){
if (the $codes_RET[$key]['TITLE'] value != the $remove variable value)
{
echo "<option value='CODE_".$codes[$key]['ID']."'>".$codes_RET[$key]['TITLE']."</option>";
}
}

ahmed24




msg:3989676
 1:03 pm on Sep 15, 2009 (gmt 0)

that works much better thanks

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved