[英]how to display the database table list in dropdown using codeigniter
[英]how to display the database table names list in codeigniter
如何使用給定的語法在 CodeIgniter 中顯示數據庫表名列表:
$tables=$this->db->query("SHOW TABLES LIKE '%Demo%'");
您必須指定database name
。
檢查這個,
SHOW TABLES FROM `database-name` LIKE '%a%'
請參閱此處的mysql 文檔
要獲取表名,
$tables=$this->db->query("SELECT t.TABLE_NAME AS myTables FROM INFORMATION_SCHEMA.TABLES AS t WHERE t.TABLE_SCHEMA = 'database name' AND t.TABLE_NAME LIKE '%a%' ")->result_array();
foreach($tables as $key => $val) {
echo $val['myTables']."<br>";// myTables is the alias used in query.
}
嘗試使用information_schema.tables
例子:
$query = $this->db->query("SELECT * FROM information_schema.tables WHERE **** ");
$result = $query->result_array();
return $result;
閱讀 本章第 19 章INFORMATION_SCHEMA
表
編輯 01
$this->db->list_tables();
$this->db->like('name', 'field');
這將把表名作為一個數組。
$tabResults = $this->db->select('TABLE_NAME')
->from('INFORMATION_SCHEMA.TABLES')
->where('TABLE_SCHEMA', 'database-name')
->like('TABLE_NAME', 'Demo')
->get()->result_array();
$tables = array_column($tabResults, 'TABLE_NAME');
然后將它們顯示為逗號分隔的列表:
echo implode(', ', $tables);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.