简体   繁体   English

在while循环中回显文本字段值

[英]echoing text field value in a while loop

echo " <table bgcolor='#d3fcfe'   align='center'>  ";

while ($row = mysql_fetch_array($result)) {

echo '</div> <tr onmouseout="this.bgColor=\'#d3fcfe\';"  onmouseover= "this   .bgColor=\'#fffdcd\';" >  ';
 $numq2=$row['username'] ;


{
echo '<td ><div class="iddiv"> <input name="" type="text" value="$numq2" />   <div>    </td> ';
}

echo '  </table>';
}

i want to output $numq2 Var's data into the value of the textfield.but something is wrong with my code.it prinout the value of textfield as "$numq2".what's wrong with my script?我想将 output $numq2 Var 的数据转换为文本字段的值。但是我的代码有问题。它将文本字段的值打印为“$numq2”。我的脚本有什么问题?

You need to use double quotes " for your strings in order for variables to be evaluated. Escape the double quotes in your HTML to have one long string.您需要为您的字符串使用双引号"以便评估变量。转义 HTML 中的双引号以获得一个长字符串。

Alternatively, you can use concatenation, allowing you to use single quotes around your HTML, and then concatenating the evaluated variables in between, like so:或者,您可以使用连接,允许您在 HTML 周围使用单引号,然后连接其间的评估变量,如下所示:

echo '<td ><div class="iddiv"> <input name="" type="text" value="'.$numq2.'" />   <div>    </td> ';

Just use your echo like this:像这样使用你的回声:

echo '<td ><div class="iddiv"> <input name="" type="text" value="' . $row['username'] . '" />   <div>    </td> ';

wrong quote use.错误的报价使用。

use either使用任何一个

echo '...value="'.$numq2.'" />...';

or或者

echo " ... value=\"$numq2\" /> ...";

This这个

echo '<td ><div class="iddiv"> <input name="" type="text" value="$numq2" />   <div>    </td> ';

should become应该成为

echo '<td ><div class="iddiv"> <input name="" type="text" value="'.$numq2.'" />   <div>    </td> ';

Notice the '.注意'. and .'.' around your $numq2在你的$numq2周围

You are using single quotes around your string.您在字符串周围使用单引号。

Anything wrapped in single quotes gets output as is, and does not get parsed.用单引号括起来的任何内容都会按原样获取 output ,并且不会被解析。

Double quotes runs your string through the parser and any variables get replaced with their values.双引号通过解析器运行您的字符串,并且任何变量都将替换为它们的值。

You need to either break out of the single quotes and concatenate your variable as follows:您需要打破单引号并连接您的变量,如下所示:

echo 'My value ' . $value . ' is the best value';

Or you need to wrap your string in double quotes and wrap your variable in { } as follows:或者您需要将字符串用双引号括起来,并将变量括在 { } 中,如下所示:

echo "My value {$value} is the best value";

try尝试

echo <td ><div class="iddiv"> <input name="" type="text" value="<?php echo $numq2;?>" />   <div></td>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM