2014-05-18 7 views
0

MySQL 데이터베이스에 텍스트 테이블 배열로 PHP 페이지에서 값을 가져 오는 SUBJECT 테이블이 있습니다. 텍스트 상자에서 문자열의 첫 번째 단어 만 표시합니다. 예 : 제목 이름 "Intro to C"이지만 텍스트 상자에는 "Intro"만 표시됩니다. , html로는텍스트 상자 배열 데이터베이스의 문자열 첫 번째 단어 만 표시

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

그렇지 않은 경우 :이 실제 코드 경우 작은 따옴표 '의 내부 데이터베이스 값을 포장해야합니다,

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

답변

1

을 - Pls는 참조 할 수 있도록 코드를 볼 해석 : 그런데

<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' /> 
+0

감사처럼 {}를 사용하여 에코 할 수 있습니다. 지금은 일하고있어. –

0

또는 당신은 단순히 좋은 도움을 사랑하는 아래

echo "<input type=text value='{$row['sub_name']}' />"; 
관련 문제