donglei1699 2018-05-12 20:35
浏览 68
已采纳

php数据显示在表格中

Evening everyone,

I'm in need of a little bit of help.

I've got a bit of quite basic PHP coding which is fetching data from a table in a MS SQL database and have come unstuck.

I'm trying to get the data to display in a table and regardless of what I do it just won't do it, the data is slapped on the page in a scrambled mess with no table headings at all (as if the browser isn't registering the table code).

<?php

$databs ='C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\DATA\MRT.mdf';

   $dbConnect = odbc_connect("MRTServ","","")
        or die("Error opening database .... use the browsers BACK button");

  if ($dbConnect)
    $dbQuery = "SELECT * FROM Callouts";
    $dbResult = odbc_exec($dbConnect,$dbQuery);


  while (odbc_fetch_row($dbResult)) {
     $Description = odbc_result($dbResult,3);    //third column
     $outcomes = odbc_result($dbResult,5);      //fifth column


        //or could retreive data by specifying the column field names 
        //specified in query
      //$Description = odbc_result($dbResult, "Description");
      //$outcomes = odbc_result($dbResult, "outcomes");
 echo "<br />";
 echo "$Description, $outcomes";
                                }
     $o = '<div id=ATtable>
           <table-id-"table1">
             <thead>
                <tr>
                    <th>Description</th>
                    <th>Outcomes</th>
                    </tr>
                </thead>
                <tbody>';

    while ( $record = odbc_fetch_array($dbResult) )
      {
          $o='<tr><td>'.[$Description].'</td><td>'.[$outcomes].'</td></tr>';

      }               

   $o='</tbody>
       </table>
       </div>';
    echo $o;

  odbc_close($dbConnect);

?>

This is the PHP code I've come up with but for the life of me cannot see where I've made the mistake or missed something.

Please can someone give me a nudge in the right direction?

Thanks, Dan

  • 写回答

3条回答 默认 最新

  • duanqiongchong0354 2018-05-12 20:41
    关注

    You are not concatenating your $o html code, use $o .= (notice the . (dot) used for concatenating the html code), in stead of $o = (which just overwrites your variable every time)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢