Jump to content

[SOLVED] displaying an array except for the one that is currently being used


Recommended Posts

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?

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.

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>

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>

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

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>

<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>

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 ;

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

<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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.