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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题