数据库值为html选择下拉列表中的“已选择”项(Database value as “selected” item in html select dropdown list)
在我的数据库中添加新记录时,我使用html选择下拉列表将用户对特定字段的选择限制为:新建,良好,公平和差。 这四个值中的一个将始终存储在该字段中。
在另一个页面上,我为用户提供了编辑该字段内容的机会。 在那里,我还将使用相同的html选择下拉列表将用户的选择限制为相同的四个值。
为了将当前值保持为默认值,我需要将其作为下拉列表中的“选定”值。 如何强制数据库中的当前值成为下拉列表中的“选定”值? 谢谢!
When adding a new record to my database I use an html select dropdown list to limit the user's choices for a particular field to: New, Good, Fair and Poor. One of these four values will always get stored in that field.
On another page I give the user a chance to edit the content of that field. There, I will also limit the user's choices to the same four values using the same html select dropdown list.
In order to maintain the current value as the default, I need it to be the "selected" value in my dropdown list. How can I force the current value in the database to be the "selected" value in my dropdown list? Thank you!
原文:https://stackoverflow.com/questions/27366374
最满意答案
我认为迄今为止的答案是不正确的。 起作用的是像
a *= b
这样的复合表达式的评估。 总之, 左边的值是在右边之前计算的 。 来自JLS (强调我的):在运行时,表达式以两种方式之一进行评估。
如果左边的操作数表达式不是数组访问表达式,则:
首先,评估左手操作数以产生变量。 如果此评估突然完成,则由于相同的原因,分配表达式会突然完成; 右侧的操作数不会被评估,也不会进行分配。
否则, 保存左侧操作数的值,然后评估右侧操作数 。 如果此评估突然完成,则由于同样的原因,分配表达式会突然完成,并且不会进行分配。
否则,左侧变量的保存值和右侧操作数的值将用于执行复合赋值运算符指示的二进制运算。 如果此操作突然完成,则由于同样的原因,赋值表达式会突然完成并且不会发生分配。
否则,二进制运算的结果将转换为左侧变量的类型,并经过值集转换(第5.1.13节)到适当的标准值集(不是扩展指数值集),结果的转换被存储到变量中。
在你的例子中:
a[0] *= a[0] = b[n ];
- 计算
a[0]
值并存储在tmp
- 评估
a[0] = b[n]
,给出b[n]
的值(并且将a[0]
的值改为b[n]
)tmp * a[0]
- 最后一步的结果被分配给
a[0]
所以,你得到的是有效
a[0] *= b[n]
。编辑:关于从左到右评估分配的困惑:我没有发现在JLS中使用的术语,恕我直言,这是不正确的(尽管它在Java教程中使用)。 它被称为正确的 - **联想*屁股JLS这样说关于任务:
有12个分配操作员; 所有都是从句法上右联合的(他们从右到左分组)。 因此,a = b = c意味着a =(b = c),它将c的值赋给b,然后将b的值赋给a。
I think the answers so far are not correct. What comes into play is the evaluation of compound expressions like
a *= b
. In short, the value of the left hand side is computed before the right hand side. From the JLS (emphasis mine):At run time, the expression is evaluated in one of two ways.
If the left-hand operand expression is not an array access expression, then:
First, the left-hand operand is evaluated to produce a variable. If this evaluation completes abruptly, then the assignment expression completes abruptly for the same reason; the right-hand operand is not evaluated and no assignment occurs.
Otherwise, the value of the left-hand operand is saved and then the right-hand operand is evaluated. If this evaluation completes abruptly, then the assignment expression completes abruptly for the same reason and no assignment occurs.
Otherwise, the saved value of the left-hand variable and the value of the right-hand operand are used to perform the binary operation indicated by the compound assignment operator. If this operation completes abruptly, then the assignment expression completes abruptly for the same reason and no assignment occurs.
Otherwise, the result of the binary operation is converted to the type of the left-hand variable, subjected to value set conversion (§5.1.13) to the appropriate standard value set (not an extended-exponent value set), and the result of the conversion is stored into the variable.
In your example:
a[0] *= a[0] = b[n ];
- value of
a[0]
is computed and stored in saytmp
a[0] = b[n]
is evaluated, giving the value ofb[n]
(and changing the value ofa[0]
tob[n]
)tmp * a[0]
is computed- the result of the last step is assigned to
a[0]
So, what you get is effectively
a[0] *= b[n]
.EDIT: About the confusion about right-to-left-evaluation of assignments: I did not find that terminology used in the JLS, and IMHO it is not correct (although it is used in the Java tutorials). It is called right-**associative* assThe JLS says this about assignments:
There are 12 assignment operators; all are syntactically right-associative (they group right-to-left). Thus, a=b=c means a=(b=c), which assigns the value of c to b and then assigns the value of b to a.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
如果你的意思是 Prove that for any real numbers, a, b such that a > b > 0, b^n is O(a^n) 然后,考虑O(a^n)的定义, 从维基 , 1) For f(x), g(x) defined on a subset of reals 2) if there exists some positive **constant** M and real number x_0, such that 3) if ABS(f(x)) <= M * ABS ...
-
Java,“a [1] * = a [1] = b [n + 1]”不按预期工作?(Java, “a[1] *= a[1] = b[n + 1]” not working as expected?)[2023-12-02]
我认为迄今为止的答案是不正确的。 起作用的是像a *= b这样的复合表达式的评估。 总之, 左边的值是在右边之前计算的 。 来自JLS (强调我的): 在运行时,表达式以两种方式之一进行评估。 如果左边的操作数表达式不是数组访问表达式,则: 首先,评估左手操作数以产生变量。 如果此评估突然完成,则由于相同的原因,分配表达式会突然完成; 右侧的操作数不会被评估,也不会进行分配。 否则, 保存左侧操作数的值,然后评估右侧操作数 。 如果此评估突然完成,则由于同样的原因,分配表达式会突然完成,并且不会进行分配。 ... -
你的funcintegrate()函数应该基本上将[a, b]区间分成n个子区间,计算所有子区间终点的f()值,然后用它们计算每个子区间的某个表达式的值,最后加起来表达式的所有值。 在每次迭代中计算的子表达式取决于您选择的特定数值积分方法,并影响性能和精度的权衡。 在最简单的情况下,表达式是端点之一的f()值乘以子区间长度的乘积。 这对应于曲线下的字段的“条形图近似”。 这是非常不准确的,一旦你成功实现它,你应该尝试更复杂的方法。 这两篇维基百科文章对许多不同的方法进行了很好的描述,每种方法都共享上述的一般 ...
-
说明图 考虑以下N = 10的情况说明,其中每个位置代表要计数的一对因子, a / N , 2和- / *表示计算该对时的算法阶段(如下所述)和. 是一个占位符,用于标记在相关阶段中未计入的对: | 1 2 3 4 5 6 7 8 9 --+-~~~-===-===----------------------- 1 ! N2- a2- a2- .2. .2. .2. .2. .2. .2. 2 ! N2- a2- a2- .2. 3 ! N2- a2- a2* 4 | N ...
-
[^\n]*$ 你可以通过简单地使用它来获得最后一行。参见演示。 https://regex101.com/r/pG1kU1/27 [^\n]*$ You can get the last line by simply using this.See demo. https://regex101.com/r/pG1kU1/27
-
您应该使用计数器来跟踪到目前为止您找到的内容。 找到b ,在计数器中添加一个。 当你找到a时,减去一个。 遍历整个列表后,计数器的最终值应为1,因为您希望b的数量比b的数量多1。 以下是如何在代码中编写代码的示例: % When we see an "a" at the head of a list, we decrement the counter. validList([a|Tail], Counter) :- NewCounter is Counter - 1, validList(Tail, ...
-
通过引用传递$ a =&$ b,$ a = $ n与$ b = $ n相同?(Passing by reference, $a = &$b, is $a=$n the same as $b=$n?)[2022-07-13]
如果您正常分配这些变量: $a = 1; $b = 2; $c = 3; 然后关联将如下所示: a --> 1 b --> 2 c --> 3 现在,如果你将$c变成$c的引用,就像这样: $a = 1; $b = 2; $c = &$a; 然后关联将如下所示: a --> 1 <--. b --> 2 | c --------/ 换句话说, $a和$c指向相同的值。 因为它们都指向相同的值,所以我们可以更改任何一个变量,它们都会指向新值。 $a = 5; echo "$a $c"; // O ... -
base b扩展n算法(base b expansion of n algorithm)[2022-06-19]
我在C中为函数编写了一个实现。 它使用指针作为输入参数,其中将放置输出(整数向量)。 该函数还返回一个整数 - 向量的逻辑大小。 #includeint toBase(int n, int b, int* answer) { assert(b > 1); q = n k = 0 while (q != 0) { answer[k] = q % b; q /= b; ++k; } retu ...