473,412 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Enum Foreaach

91
I have an enum mysql field with a null value ''. I need that null value to be disabled in the dropdown list however it is showing the html <option> as <option/> Here is the code I have.

Expand|Select|Wrap|Line Numbers
  1. foreach($enums as $key)
  2.                 {
  3.                         echo "<option ".$func->iif($key==$results['Group'],'selected','').">".$func->makeSafe($key)."</option>";
  4.                 }
I have also tried the following with no success either.
Expand|Select|Wrap|Line Numbers
  1. foreach($enums as $key)
  2.                 {
  3.                     if (is_null($key) || !isset($key))
  4.                         echo "<option></option>";
  5.                     else
  6.                         echo "<option ".$func->iif($key===$results['Group'],'selected').">".$func->makeSafe($key)."</option>";
  7.                 }
anyone know why this displays the null option as <option/> and not <option></option>?
Mar 31 '08 #1
5 3012
arggg
91
I have tried adding slashes to escape the quotes but still no luck.
Mar 31 '08 #2
TheServant
1,168 Expert 1GB
How about:
[PHP]<?php
foreach($enums as $key)
{
?>
<option <?php echo ( $func->iif($key==$results['Group'],'selected','') ); ?> >
<?php echo ( $func->makeSafe($key) ); ?> </option>
}[/PHP]

Or something like that? Just further separating the html and php?
Mar 31 '08 #3
Markus
6,050 Expert 4TB
I have an enum mysql field with a null value ''. I need that null value to be disabled in the dropdown list however it is showing the html <option> as <option/> Here is the code I have.

Expand|Select|Wrap|Line Numbers
  1. foreach($enums as $key)
  2.                 {
  3.                         echo "<option ".$func->iif($key==$results['Group'],'selected','').">".$func->makeSafe($key)."</option>";
  4.                 }
I have also tried the following with no success either.
Expand|Select|Wrap|Line Numbers
  1. foreach($enums as $key)
  2.                 {
  3.                     if (is_null($key) || !isset($key))
  4.                         echo "<option></option>";
  5.                     else
  6.                         echo "<option ".$func->iif($key===$results['Group'],'selected').">".$func->makeSafe($key)."</option>";
  7.                 }
anyone know why this displays the null option as <option/> and not <option></option>?
I don't understand how this is happening...
You're not echoing '<option/>' anywhere, so it shouldnt be printed.
Mar 31 '08 #4
bucabay
18
I have an enum mysql field with a null value ''. I need that null value to be disabled in the dropdown list however it is showing the html <option> as <option/> Here is the code I have.

Expand|Select|Wrap|Line Numbers
  1. foreach($enums as $key)
  2.                 {
  3.                         echo "<option ".$func->iif($key==$results['Group'],'selected','').">".$func->makeSafe($key)."</option>";
  4.                 }
I have also tried the following with no success either.
Expand|Select|Wrap|Line Numbers
  1. foreach($enums as $key)
  2.                 {
  3.                     if (is_null($key) || !isset($key))
  4.                         echo "<option></option>";
  5.                     else
  6.                         echo "<option ".$func->iif($key===$results['Group'],'selected').">".$func->makeSafe($key)."</option>";
  7.                 }
anyone know why this displays the null option as <option/> and not <option></option>?
How are you viewing the HTML source?
Some browsers will interpret a <tag></tag> as <tag />.

[HTML]if (is_null($key) || !isset($key))[/HTML]

Is useless here. isset($key) will always return true. NULL converts to an empty string with echo() so there is no need to test if its null, then write out the literal <option></option>.
Apr 1 '08 #5
arggg
91
I found where the issue was with the <option/> It appears if there is no text between the <option></option> tags it will change the tags to <option/> It must be the browsers or something... Who knows so what I did was if the value = '' then just do <option value=''>[None]</option> to fix this problem.
Apr 1 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
18
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
2
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by their value, i.e., I want to input 6 into a function...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
1
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.