我正在尝试将每个列的行值打印到没有null的文本区域?如果我在一段时间内完成它,那么我就完美了,但我需要在HTML代码之外打印它。我怎么得到这个。
$sdata = mysql_query("select (case when `EntryType` like '%Buildup%' then `EntryDescription` end) As cia,
(case when `EntryType` like '%prelim%' or '%grinding%' then `EntryDescription` end) As grind,
(case when `EntryType` like '%Covers%' then `EntryDescription` end) As covers,
(case when `EntryType` like '%prelim%' or '%grinding%' then `EntryDescription` end) As buildup,
(case when `EntryType` like '%Comment%' then `EntryDescription` end) As comments
from `selectitem`
JOIN `patient` on `patient`.`RecdNo` = `selectitem`.`RecordID`
WHERE `patient`.`PatientID`='".$_GET['edit']."'");
while($data = mysql_fetch_array($sdata) ){
}
HTML代码:
<tr>
<td colspan="2"> <textarea rows="2" name="cia" style="width:90%;"><?php echo $data['cia']; ?></textarea> </label> </td>
<td colspan="2"> <textarea rows="2" name="grind" style="width:100%;"><?php ?> </textarea> </td>
</tr>
<tr>
<td colspan="2"><i>Covers</i> </td>
<td colspan="2"><i>Build Up</i> </td>
</tr>
<tr>
<td colspan="2"> <textarea rows="2" name="covers" style="width:90%;"><?php ?> </textarea> </label> </td>
<td colspan="2"> <textarea rows="2" name="buildup" style="width:100%;"><?php ?> </textarea> </td>
</tr>
<tr>
<td colspan="4"> <i>Comments</i> </td>
</tr>
<tr>
<td colspan="4"> <textarea rows="2" name="comments" style="width:100%;"><?php ?> </textarea></td>
</tr>
答案 0 :(得分:1)
您仍然需要使用while循环,但是将值分配给这样的变量:
$cia ="";
$grind = "";
$count = mysql_num_rows($sdata); //count rows
$i=1; // set an iteration counter
while($data = mysql_fetch_array($sdata) ){
if($i < $count){ // check if not last row and add newline if true
$nl = "\r\n";
} else {
$nl = ""; // no newline if last row
}
if($data["cia"]){
$cia .= $data["cia"] . $nl; // remember to change "\r\n" to $nl in all of these places
}
if($data["grind"]){
$grind.= $data["grind"] . $nl;
}
$i++; //increase iteration counter
}
然后输出textareas中的变量:
<tr>
<td colspan="2"> <textarea rows="2" name="cia" style="width:90%;"><?php echo $cia; ?></textarea> </label> </td>
<td colspan="2"> <textarea rows="2" name="grind" style="width:100%;"><?php echo $grind; ?> </textarea> </td>
</tr>
<tr>
<td colspan="2"><i>Covers</i> </td>
<td colspan="2"><i>Build Up</i> </td>
</tr>
<tr>
<td colspan="2"> <textarea rows="2" name="covers" style="width:90%;"><?php ?> </textarea> </label> </td>
<td colspan="2"> <textarea rows="2" name="buildup" style="width:100%;"><?php ?> </textarea> </td>
</tr>
<tr>
<td colspan="4"> <i>Comments</i> </td>
</tr>
<tr>
<td colspan="4"> <textarea rows="2" name="comments" style="width:100%;"><?php ?> </textarea></td>
</tr>