php - 文本框数组仅显示数据库中字符串的第一个单词

标签 php mysql

我在 MySQL 数据库中有一个 SUBJECT 表,我在带有文本框数组的 php 页面中检索其值。同时检索它仅显示文本框中字符串的第一个单词。 例如——主题名称“C 简介”,但在文本框中仅显示“简介”。请参阅引用代码--

     <table width="400" border="1">
     <tr>
     <td colspan="4" valign="top"><div align="center" class="style4">Subject(s) Details</div></td>
      </tr>
      <tr>
<td width="87"><strong><span class="style1">Select </span></strong></td>
<td width="87"><strong><span class="style1">Subject ID </span></strong></td>
<td width="270"><strong><span class="style1">Subject Name </span></strong></td>
 </tr>
 <?php
            $i=0;
            $result = mysql_query("select sub_id,sub_name from subject where crs_id='$cid' and sem_id='$smid' order by sub_id asc")
            or 
            die(mysql_error());

            while($row = mysql_fetch_array($result))
            {
?>
  <tr>
<td><span class="style1"><?php echo "<input name=t1[] type=checkbox value=".$i." checked />"; ?></span></td>
<td><span class="style1"><?php echo "<input name=t2[] size=15 type=text  value=".$row['sub_id']." />"; ?></span></td>
<td><span class="style1"><?php echo "<input name=t3[] size=30 type=text  value=".$row['sub_name']." />"; ?></span></td>
 </tr>
  <?php
        $i++;
        }
 ?>
   <tr>
<td colspan="4"><div align="center"><input name="submit" type="Submit" value="Update Subject(s)" />
</div></td>
  </tr>
 </table>

最佳答案

如果这是您的实际代码,您需要将数据库值括在单引号内 ':

<?php echo "<input name=t3[] size=30 type=text  value='".$row['sub_name']."' />"; ?>

如果不是,则 html 被解释为:

<input name=t3[] size=30 type=text value=Intro to C />

顺便说一句,这是所有 html 属性的最佳实践:

<?php echo "<input name='t3[]' size='30' type='text'  value='".$row['sub_name']."' />"; ?>

结果:

<input name='t3[]' size='30' type='text'  value='Intro to C' />

关于php - 文本框数组仅显示数据库中字符串的第一个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23718811/

相关文章:

php - 如何使用 PHP PDO 在 mysql 中插入未知数量的列

php - 基本正则表达式帮助

JavaScript - 如何从下拉选择中执行特定查询?

php - 比较两个关联数组的键顺序

php - 从 Linux 连接到 MsSQL 数据库

php - 即使设置了submit_registration_form_button,也将用户重定向到index.php

php - 声明应与 PHP 7 兼容

mysql - 通过其他表中的字符串匹配分配产品类别

mysql - 如果从主表中删除行,则从其他表中删除行

mysql - 查询以查看订阅是否在两个日期范围内有效