DBテーブルに格納されているデータ
Array ( [0] => Array ( [DBS] => Array ( [DB_ID] => 1 [NAME] =>default ) ) [1] => Array ( [DBS] => Array ( [DB_ID] => 2 [NAME] => temp ) ) 以下略
TBLSテーブルに格納されているデータ
Array ( [0] => Array ( [TBLS] => Array ( [DB_ID] => 1 [TBL_ID] => 1001 [TBL_NAME] => tesut1_abc ) ) [1] => Array ( [TBLS] => Array ( [DB_ID] => 2 [TBL_ID] => 1002 [NAME] => test2_def ) )
考えているクエリ
select * from DBS;(全DB一覧取得) クリックされたらそのDB_IDを取得する $db_id=DB_ID; select * from TBLS where DB_ID =$db_id;(テーブル一覧取得)
controller <?php class EntityController extends AppController { var $name = 'Entity'; var $components = array('RequestHandler','Auth','Common'); var $user; function index() { $this->Entity->setDataSource('hive'); //$this->layout='entity';//使用するレイアウト //DB一覧取得 $sql ="select * from DBS;"; $result= $this->Entity->query($sql); $this->set('para', $result); } public function entity_tbl($db_id){ $this->Entity->setDataSource('hive'); $sql ="select * from TBLS where DB_ID =$db_id;"; $result= $this->Entity->query($sql); $this->set('para', $result); } }
index.ctp <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title> <link rel="stylesheet" href=""> </head> <body> <h2>DB一覧</h2> <ul> <?php foreach($para as $name): ?> <li><?php echo h($name['DBS']['NAME']) ?></li> <?php $db_id=$name['DBS']['DB_ID'] ?> <!--<?php debug($db_id); ?>--> <?php endforeach; ?> </ul> <?php echo $this->Html->link('テーブル一覧',array('action'=>'entity_tbl',$name['DBS']['DB_ID'])); ?> </body> </html>
entiti_tbl.ctp <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title> <link rel="stylesheet" href=""> </head> <body> <h2>テーブル一覧</h2> <ul> <?php foreach($para as $name): ?> <li><?php echo h($name['TBLS']['TBL_NAME']) ?></li> <!--<?php $db_id=$name['DBS']['DB_ID'] ?>--> <!--<?php debug($db_id); ?>--> <?php endforeach; ?> </ul> </body> </html>
現在ここまで出来ております。
次にこの表示されているDBのNAMEがクリックされたら
その$nameから
$db_id=DB_ID;でDB_IDを取得し
select * from TBLS where DB_ID =$db_id;(テーブル一覧取得)
のクエリが流れるようにしたいのですが
どうしたらこの表示されているのをNAMEデータをリンクにしさらに
select * from TBLS where DB_ID =$db_id;
が流れTBLSのTBL_NAMEを表示することができますでしょうか?
タイトルはちゃんと書いてください。