douliao8318 2010-11-11 05:37
浏览 35
已采纳

格式化使用PHP / PEAR Structures_DataGrid和HTML_Table生成的表

I've been working through some examples in a book using pear for the first time... so far it seems pretty cool, but I'm having a small problem where I need to tweak the formatting of one particular column of the table generated from Structures_DataGrid & HTML_Table - specifically I need it to not wrap the text in a cell at the hyphen - which I think I could do using 'nowrap' and html/css - but so far I'm not seeing how to pass that sort of formatting to just one column in the table...

Any suggestions?

Added source code below:

    <?php
  // Include the DB access credentials
  require 'dbcred.php';

  // Include the PEAR Structures_DataGrid class
  require 'Structures/DataGrid.php';

  // instantiate grid for 10 records per page
  $datagrid = new Structures_DataGrid(10);

  // Define our Datasource options, in this case PDO MySQL
  $options = array('dsn' => "mysql://$user:$password@$db_host/$db_name");

  // Define the Query
  $sql = "SELECT * FROM contact_info";

  // Bind the Query to our Datagrid
  $bind = $datagrid->bind($sql, $options);
  // Test for Errors
  if (PEAR::isError($bind))
  {
    /*error_log('DataGrid Error: '. $bind->getMessage());
    $gridsource = 'Foo';*/
    echo $bind -> getMessage();
  }
  else
  {
    // Define our Column labels, using a 'column' => 'Label' format
    $columns = array(
        'title' => 'Title',
        'first_name' => 'First Name',
        'mid_init' => 'Mid. Init.',
        'last_name' => 'Last Name',
        'suffix' => 'Suffix',
        'street_address' => 'Street Address',
        'city' => 'City',
        'state_prov' => 'State/Province',
        'post_code' => 'Postal Code',
        'phone_pri' => 'Phone (Pri)',
        'phone_alt' => 'Phone (Alt)',
        'email' => 'E-Mail',
    );
    $datagrid->generateColumns($columns);
    // Some more options, for our renderer
    $renderer_options = array(
        'sortIconASC' => '&uArr;',
        'sortIconDESC' => '&dArr;',
        'headerAttributes' => array('bgcolor' => '#E3E3E3'),
        'evenRowAttributes' => array('bgcolor' => '#A6A6A6'),
    );
    $datagrid->setRendererOptions($renderer_options);

    // Add some final attributes to our table
    $renderer = $datagrid->getRenderer();
    $renderer->setTableAttribute('cellspacing', 0);
    $renderer->setTableAttribute('cellpadding', 5);
    $renderer->setTableAttribute('border', 1);
    // Render the table, be sure to check for errors 
    $gridbody = $datagrid->getOutput();
    if (PEAR::isError($gridbody))
    {
      error_log('DataGrid render error: ' . $gridbody->getMessage());
      $gridbody = '';
    }
    // Finally, render the pager, again checking for errors
    $gridpager = $datagrid->getOutput(DATAGRID_RENDER_PAGER);
    if (PEAR::isError($gridpager))
    {
      error_log('DataGrid render error: ' . $gridpager->getMessage());
      $gridpager = '';
    }
    $gridsource = $gridbody . $gridpager;
  }
?>
<!DOCTYPE html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>PEAR::Structures_DataGrid</title>
    <meta http-equiv="Content-type"
        content="text/html; charset=iso-8859-1" />
    <style type="text/css">
      body {
        font-family: Tahoma, Arial, Helvetica, sans-serif;
        font-size: 11px;
      }
      h1 {
        font-size: 1.2em;
        color: navy
      }
      th {
          white-space: no-wrap;
      }
    </style>
  </head>
  <body>
    <h1>PEAR::Structures_DataGrid</h1>
    <?php echo $gridsource ?>
  </body>
</html>
  • 写回答

1条回答 默认 最新

  • dtgta48604 2010-11-11 15:19
    关注

    Don't know what pear is but: You can format columns like this in html:

    <table>
      <col style="background: green;" />
      <col />
      <tr>
        <td>First TD of first TR</td>
        <td>Second TD of first TR</td>
      </tr>
      <tr>
        <td>First TD of second TR</td>
        <td>Second TD of second TR</td>
      </tr>
    </table>
    

    That makes the background of the first column green.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog