shadiadiph Posted May 2, 2009 Share Posted May 2, 2009 Problem is this the following code calls the folder names from the database. <? while($row=mysql_fetch_array($resultfolder)) { $folders = ucwords($row["folder"]); echo '<option value="'.$folders.'">'.$folders.'</option>'; } ?> If I am already in folder inbox it is showing inbox as an option also how can i make it to display everything except inbox in the $folders array? Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/ Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Preferably, don't use PHP shorthand tags. <?php while($row=mysql_fetch_array($resultfolder)) { $folders = ucwords($row["folder"]); if (strcmp($folders, "inbox") != 0) echo '<option value="'.$folders.'">'.$folders.'</option>'; } ?> Something like that? Though, it's better to do it in the SQL. Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824000 Share on other sites More sharing options...
shadiadiph Posted May 2, 2009 Author Share Posted May 2, 2009 that works great in this instance it has to be done this way as $folder is inbox $folders is being called from a different table in this instance but it could change so i will use this method thanks. Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824004 Share on other sites More sharing options...
shadiadiph Posted May 2, 2009 Author Share Posted May 2, 2009 sorry there are a few more questions so i will carry on in this thread. Also is there anyway of removing the selected options from the dropdown list? In this instance the code currently looks like this and i am trying to get rid of 'Folder' from the dropdown list also. <select name="changefolder" onchange="submit()"> <option value="" selected="selected">Folder</option> <?php while($row=mysql_fetch_array($resultfolder)) { $folders = ucwords($row["folder"]); if (strcmp($folders, "$folder") != 0) echo '<option value="'.$folders.'">'.$folders.'</option>'; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824012 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 That's stupid. That would remove all of them because something will always be equal to itself. You can do: <select name="changefolder" onchange="submit()"> <option value="" selected="selected">Folder</option> <?php $exclusions = array('inbox', 'folder2'); while($row=mysql_fetch_array($resultfolder)) { $folders = ucwords($row["folder"]); if (!in_array($folders, $exclusions)) echo '<option value="'.$folders.'">'.$folders.'</option>'; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824014 Share on other sites More sharing options...
shadiadiph Posted May 2, 2009 Author Share Posted May 2, 2009 mm the first works the second way kind of works to remove a folder named if the name is known. The value of $folder and $folders are being called from two different tables $folder might not always be 'inbox' it could be 'myfolder' or whatever the user has added. so i can't use <select name="changefolder" onchange="submit()"> <option value="" selected="selected">Folder</option> <?php $exclusions = array('$folder', 'Sent'); while($row=mysql_fetch_array($resultfolder)) { $folders = ucwords($row["folder"]); if (!in_array($folders, $exclusions)) echo '<option value="'.$folders.'">'.$folders.'</option>'; } ?> </select> it doesn't work as the $folder currently in use could be 'inbox' could be named anything Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824033 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Oh, well you should have said so. Can you lay out the two table structures? Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824039 Share on other sites More sharing options...
shadiadiph Posted May 2, 2009 Author Share Posted May 2, 2009 this actually works to exclude the currently viewed folder the first way you showed me but I also want to exclude 'Sent' also <select name="changefolder" onchange="submit()"> <option value="" selected="selected">Folder</option> <?php while($row=mysql_fetch_array($resultfolder)) { $folders = ucwords($row["folder"]); if (strcmp($folders, $folder) != 0) echo '<option value="'.$folders.'">'.$folders.'</option>'; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824041 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 <select name="changefolder" onchange="submit()"> <option value="" selected="selected">Folder</option> <?php $exclusions = array($folder, 'Sent'); while($row=mysql_fetch_array($resultfolder)) { $folders = ucwords($row["folder"]); if (!in_array($folders, $exclusions)) echo '<option value="'.$folders.'">'.$folders.'</option>'; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824042 Share on other sites More sharing options...
shadiadiph Posted May 2, 2009 Author Share Posted May 2, 2009 here are my two tables where $folders is being called from if the user adds a folder it is stored here -- -- Table structure for table `mailfoldertbl` -- CREATE TABLE IF NOT EXISTS `mailfoldertbl` ( `folderID` int(11) NOT NULL auto_increment, `userID` int(255) default NULL, `username` varchar(255) NOT NULL default '', `folder` varchar(255) NOT NULL default '', `unread` int(255) NOT NULL default '0', `messtotal` int(255) NOT NULL default '0', PRIMARY KEY (`folderID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ; where $folder is being called from depends which mailfolder the message is currently in -- -- Table structure for table `mailtbl` -- CREATE TABLE IF NOT EXISTS `mailtbl` ( `mailID` int(11) NOT NULL auto_increment, `messagesize` int(255) NOT NULL default '0', `fromuserID` int(255) default NULL, `touserID` int(255) default NULL, `fromusername` varchar(55) NOT NULL default '', `tousername` varchar(55) NOT NULL default '', `seen` varchar(255) default NULL, `mailfolder` varchar(55) NOT NULL default '', `subject` varchar(255) NOT NULL default '', `message` varchar(255) NOT NULL default '', `fileatt1` varchar(255) default NULL, `fileatt2` varchar(255) default NULL, `fileatt3` varchar(255) default NULL, `fileatt4` varchar(255) default NULL, `fileatt5` varchar(255) default NULL, `timereceived` time default NULL, `datereceived` date default NULL, `timesent` time default NULL, `datesent` date default NULL, `alert` varchar(100) default NULL, `checked` varchar(100) default NULL, `ipaddress` varchar(55) NOT NULL default '', PRIMARY KEY (`mailID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824044 Share on other sites More sharing options...
shadiadiph Posted May 2, 2009 Author Share Posted May 2, 2009 awesome thanks Ken2k7 for the help just wondering is there anyway to remove the selected folder in this instance 'Folder' from the dropdown list I always find that annoying in drop down lists why does it have to display the top one twice Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824045 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 <select name="changefolder" onchange="submit()"> <?php $exclusions = array($folder, 'Sent'); while($row=mysql_fetch_array($resultfolder)) { $folders = ucwords($row["folder"]); if (!in_array($folders, $exclusions)) echo '<option value="'.$folders.'">'.$folders.'</option>'; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824049 Share on other sites More sharing options...
shadiadiph Posted May 2, 2009 Author Share Posted May 2, 2009 mm ok not exactly what i meant but thanks for the help Ken2k7 Quote Link to comment https://forums.phpfreaks.com/topic/156481-solved-displaying-an-array-except-for-the-one-that-is-currently-being-used/#findComment-824057 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.