2014-06-10 29 views
0

我想從另一個表的行此創建一個表名的新表是我做的,到目前爲止無法創建表與表的名稱空間動態

<?php 
header('content-type:application/json; charset=utf-8'); 
include "db.php"; 
$sql=mysql_query("SELECT * from tb1"); 
while($row=mysql_fetch_assoc($sql)) 
$out[] = $row['title'];//see below what it outs 
for($i=0;$i<=count($out);$i++) 
{ 
$query = 'CREATE TABLE '.$out[$i].' (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255))'; 
$sqls = mysql_query($query); 
} 
// if (!$sqls) { 
    //die('Invalid query: ' . mysql_error()); 
//} 

?> 

$出[]有一個像

輸出
word one word two word three 


Note:its not a single title it has three words 
word one-->title one 
word two -->title two 
word three-->title three 
+1

[MySQL的 「架構對象名稱」](http://dev.mysql.com/doc/refman/5.6/en/identifiers.html)。養成閱讀文檔的習慣。 –

+0

@ SverriM.Olsen我會跟着它 – Vinod

回答

1

不推薦表名,列名和空間,但如果真的需要與空間中創建,然後需要將其包裹在反引號

$query = 'CREATE TABLE `'.$out[$i].'` 

http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

+0

偉大的權利,但我想知道更多關於反引號我沒有在鍵盤上找到它...它是什麼... – Vinod

+1

http://superuser.com/questions/254076/how-do-i-type-the-tick-and-backtick-characters-on-windows –

+0

發現它謝謝...它在tilde鍵 – Vinod