1

我希望从表格中获取数据test2test3显示在网页上,但我一直看到一个空白屏幕。

$query = "INSERT INTO test2,test3 VALUES(' ','$title','$stdate','$endate',' ',' ',' ',' ',' ','$fileName','$fileSize','$fileType',' ','$desc',' ','$postuser')";

} } }
else {   
$query = "INSERT INTO test2,test3 VALUES(' ','$title','$stdate','$endate',' ',' ',' ',' ',' ','$fileName','$fileSize','$fileType',' ','$desc',' ','$postuser')";

}    
mysql_query($query) or die('Error, query failed.         '. mysql_error());

}   

$query4=" SELECT * FROM test2,test3";
4

3 回答 3

1

您的方法本质上是错误的,但是,这里是更正的代码:

$query = "INSERT INTO test2 VALUES(' ','$title','$stdate','$endate',' ',' ',' ',' ',' ','$fileName','$fileSize','$fileType',' ','$desc',' ','$postuser')";

} } }
else {   
$query = "INSERT INTO test3 VALUES(' ','$title','$stdate','$endate',' ',' ',' ',' ',' ','$fileName','$fileSize','$fileType',' ','$desc',' ','$postuser')";

}    
mysql_query($query) or die('Error, query failed.         '. mysql_error());

}   

$query4="SELECT * FROM test2 UNION ALL SELECT * FROM test3";
于 2013-08-10T23:40:30.520 回答
0

这个怎么样

$dh = mysql_connect('localhost','root','') or die(mysql_error());

$db1 = mysql_select_db('test2',$dh);
mysql_query("SELECT * FROM tableFromTest2",$db1);

$db2 = mysql_select_db('test3',$dh);
mysql_query("SELECT * FROM tableFromTest3",$db2);

mysql_close($dh);

或者

mysql_connect('localhost','root','') or die(mysql_error());

mysql_query("USE test2");
mysql_query("SELECT * FROM tableFromTest2");

mysql_query("USE test3");
mysql_query("SELECT * FROM tableFromTest3");

mysql_close($dh);
于 2013-08-10T23:33:01.233 回答
0

看起来你想要一个简单的联合:

SELECT * FROM test2
UNION
SELECT * FROM test3

假设 test2 和 test3 的表结构相似(因为它们在您的示例代码中)。

当然,由于您将其插入两次(每个表一次),您可能希望将其取回两次 - 所以使用 UNION ALL。您也可以使用 ORDER BY 和 DISTINCT 优化。

于 2013-08-10T23:35:08.220 回答