PHPのお勉強



Structures_DataGrid(PEAR)を利用@PHP

Structures_DataGridを利用します。
名前の通り、表を作成できます。
DBから取得したデータを元に表が作成可能です。

pear install Structures_DataGridでインストールします。

DataSourceとRendererが必要なので、以下もインストールします。
pear install Structures_DataGrid_DataSource_MDB2
pear install Structures_DataGrid_Renderer_Pager
pear install Structures_DataGrid_Renderer_HTMLTable

以下は、mysqlに接続し、
select文を発行して、Structures_DataGridにbindします。
bind後は、renderでデータを表示します。


<?php

require("Structures/DataGrid.php");

//DSN
$dsn = "mysql://root:pass@localhost/dbname";

//Structures_DataGridを生成
$datagrid =& new Structures_DataGrid();

//DSNをオプションに設定
$options = array("dsn" => $dsn);

//DataBind処理
$datagrid->bind("SELECT * FROM tablename", $options);

//render
$datagrid->render();

?>




Copyright (C) PHPのお勉強. All Rights Reserved.