我想创建一个新表,其中包含来自另一个表格的表名,这是我到目前为止所做的
<?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());
//}
?>
$ out []的输出类似
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
答案 0 :(得分:1)
不推荐使用带空格的表名,列名,但如果确实需要使用空格创建,则需要将其包含在反引号中
$query = 'CREATE TABLE `'.$out[$i].'`