I'm trying to print each column row values into a text area without null? If I do it within the while then I got perfect but I need print it in HTML code outside of the while. How do I get this.
$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 Code Here:
<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>
You still need to use the while loop, but assign the values to variables like this:
$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 = "
";
} else {
$nl = ""; // no newline if last row
}
if($data["cia"]){
$cia .= $data["cia"] . $nl; // remember to change "
" to $nl in all of these places
}
if($data["grind"]){
$grind.= $data["grind"] . $nl;
}
$i++; //increase iteration counter
}
Then you output the variables in the 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>