duanlu0075 2016-03-16 19:50
浏览 42
已采纳

将数组列值打印到文本区域中,不带空值

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']."'");

Query Output: enter image description here

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>
  • 写回答

1条回答 默认 最新

  • doupai8533 2016-03-16 20:06
    关注

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)