如何在一个php中显示两个数据表??但这只是一个表格记录
我试图将两个表记录放在一个PHP中,但当包含两个PHP文件时,它只查看其中一个记录? echo将成为未定义索引时的另一个文件。如何在一个php中显示两个数据表??但这只是一个表格记录,php,Php,我试图将两个表记录放在一个PHP中,但当包含两个PHP文件时,它只查看其中一个记录? echo将成为未定义索引时的另一个文件。 Main.php <?php include"Location.php"; include"Fullname.php"; ?> <html> <head> <table id ="table"> <tr> <th>Customer Name</th> <th>Locati
Main.php
<?php
include"Location.php";
include"Fullname.php";
?>
<html>
<head>
<table id ="table">
<tr>
<th>Customer Name</th>
<th>Location From</th>
<th>Location To</th>
<th>Departure Date</th>
<th>Return Date</th>
<th>Travel</th>
</tr>
<?php
if(isset($result ) && !empty($result )){
while($row = $result->fetch_assoc()){
echo "
<tr>
<td>{$row['Fullname']}</td>}}
<td>{$row['LocationFrom']}</td>
<td>{$row['LocationTo']}</td>
</tr>\n";
}
}
?>
</table>
</body>
</html>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT * FROM booking";
$result = mysqli_query($conn,$sql);
mysqli_close($conn);
}
?>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT Fullname FROM useraccount";
$result = mysqli_query($conn,$sql);
mysqli_close($conn);
}
?>
a = 3
a = 4
<?php
result = []
include"Location.php";
include"Fullname.php";
?>
<html>
<head>
<table id ="table">
<tr>
<th>Customer Name</th>
<th>Location From</th>
<th>Location To</th>
<th>Departure Date</th>
<th>Return Date</th>
<th>Travel</th>
</tr>
<?php
if(isset($result ) && !empty($result )){
while($location_row = $result[0]->fetch_assoc() and $fullname_row = $result[1]->fetch_assoc()){
echo "
<tr>
<td>{$fullname_row['Fullname']}</td>}}
<td>{$location_row['LocationFrom']}</td>
<td>{$location_row['LocationTo']}</td>
</tr>\n";
}
}
?>
</table>
</body>
</html>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT * FROM booking";
array_push($result, mysqli_query($conn,$sql));
mysqli_close($conn);
}
?>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT Fullname FROM useraccount";
array_push($result, mysqli_query($conn,$sql));
mysqli_close($conn);
}
?>
客户名称
位置从
位置到
离港日
返回日期
旅行
它只显示一个表,因为您正在重写该值。
例如,这就是你正在做的事情
file1.php
<?php
include"Location.php";
include"Fullname.php";
?>
<html>
<head>
<table id ="table">
<tr>
<th>Customer Name</th>
<th>Location From</th>
<th>Location To</th>
<th>Departure Date</th>
<th>Return Date</th>
<th>Travel</th>
</tr>
<?php
if(isset($result ) && !empty($result )){
while($row = $result->fetch_assoc()){
echo "
<tr>
<td>{$row['Fullname']}</td>}}
<td>{$row['LocationFrom']}</td>
<td>{$row['LocationTo']}</td>
</tr>\n";
}
}
?>
</table>
</body>
</html>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT * FROM booking";
$result = mysqli_query($conn,$sql);
mysqli_close($conn);
}
?>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT Fullname FROM useraccount";
$result = mysqli_query($conn,$sql);
mysqli_close($conn);
}
?>
a = 3
a = 4
<?php
result = []
include"Location.php";
include"Fullname.php";
?>
<html>
<head>
<table id ="table">
<tr>
<th>Customer Name</th>
<th>Location From</th>
<th>Location To</th>
<th>Departure Date</th>
<th>Return Date</th>
<th>Travel</th>
</tr>
<?php
if(isset($result ) && !empty($result )){
while($location_row = $result[0]->fetch_assoc() and $fullname_row = $result[1]->fetch_assoc()){
echo "
<tr>
<td>{$fullname_row['Fullname']}</td>}}
<td>{$location_row['LocationFrom']}</td>
<td>{$location_row['LocationTo']}</td>
</tr>\n";
}
}
?>
</table>
</body>
</html>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT * FROM booking";
array_push($result, mysqli_query($conn,$sql));
mysqli_close($conn);
}
?>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT Fullname FROM useraccount";
array_push($result, mysqli_query($conn,$sql));
mysqli_close($conn);
}
?>
file2.php
<?php
include"Location.php";
include"Fullname.php";
?>
<html>
<head>
<table id ="table">
<tr>
<th>Customer Name</th>
<th>Location From</th>
<th>Location To</th>
<th>Departure Date</th>
<th>Return Date</th>
<th>Travel</th>
</tr>
<?php
if(isset($result ) && !empty($result )){
while($row = $result->fetch_assoc()){
echo "
<tr>
<td>{$row['Fullname']}</td>}}
<td>{$row['LocationFrom']}</td>
<td>{$row['LocationTo']}</td>
</tr>\n";
}
}
?>
</table>
</body>
</html>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT * FROM booking";
$result = mysqli_query($conn,$sql);
mysqli_close($conn);
}
?>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT Fullname FROM useraccount";
$result = mysqli_query($conn,$sql);
mysqli_close($conn);
}
?>
a = 3
a = 4
<?php
result = []
include"Location.php";
include"Fullname.php";
?>
<html>
<head>
<table id ="table">
<tr>
<th>Customer Name</th>
<th>Location From</th>
<th>Location To</th>
<th>Departure Date</th>
<th>Return Date</th>
<th>Travel</th>
</tr>
<?php
if(isset($result ) && !empty($result )){
while($location_row = $result[0]->fetch_assoc() and $fullname_row = $result[1]->fetch_assoc()){
echo "
<tr>
<td>{$fullname_row['Fullname']}</td>}}
<td>{$location_row['LocationFrom']}</td>
<td>{$location_row['LocationTo']}</td>
</tr>\n";
}
}
?>
</table>
</body>
</html>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT * FROM booking";
array_push($result, mysqli_query($conn,$sql));
mysqli_close($conn);
}
?>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT Fullname FROM useraccount";
array_push($result, mysqli_query($conn,$sql));
mysqli_close($conn);
}
?>
因此,当您同时包含这两个文件时file2.php将覆盖file1.php的值
因此,您需要做的是将file2.php的变量设置为不同的名称。所以
b = 4
现在,在不同的变量中都有值3和4。
对你来说,就这么做吧
Main.php
<?php
include"Location.php";
include"Fullname.php";
?>
<html>
<head>
<table id ="table">
<tr>
<th>Customer Name</th>
<th>Location From</th>
<th>Location To</th>
<th>Departure Date</th>
<th>Return Date</th>
<th>Travel</th>
</tr>
<?php
if(isset($result ) && !empty($result )){
while($row = $result->fetch_assoc()){
echo "
<tr>
<td>{$row['Fullname']}</td>}}
<td>{$row['LocationFrom']}</td>
<td>{$row['LocationTo']}</td>
</tr>\n";
}
}
?>
</table>
</body>
</html>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT * FROM booking";
$result = mysqli_query($conn,$sql);
mysqli_close($conn);
}
?>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT Fullname FROM useraccount";
$result = mysqli_query($conn,$sql);
mysqli_close($conn);
}
?>
a = 3
a = 4
<?php
result = []
include"Location.php";
include"Fullname.php";
?>
<html>
<head>
<table id ="table">
<tr>
<th>Customer Name</th>
<th>Location From</th>
<th>Location To</th>
<th>Departure Date</th>
<th>Return Date</th>
<th>Travel</th>
</tr>
<?php
if(isset($result ) && !empty($result )){
while($location_row = $result[0]->fetch_assoc() and $fullname_row = $result[1]->fetch_assoc()){
echo "
<tr>
<td>{$fullname_row['Fullname']}</td>}}
<td>{$location_row['LocationFrom']}</td>
<td>{$location_row['LocationTo']}</td>
</tr>\n";
}
}
?>
</table>
</body>
</html>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT * FROM booking";
array_push($result, mysqli_query($conn,$sql));
mysqli_close($conn);
}
?>
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT Fullname FROM useraccount";
array_push($result, mysqli_query($conn,$sql));
mysqli_close($conn);
}
?>
客户名称
位置从
位置到
离港日
返回日期
旅行
因为您将结果设置为一个变量名!'$result',添加到这个变量中,表的名称,您很高兴看到Go您能告诉我如何做吗?只需将result from location表设置为$result\u location,并将result from Fullname设置为$result\u fullnamechange,然后在主php中,$result更改为wht?注意:在第29行的C:\xampp\htdocs\Lesson php\assignment\Location.php中,只有变量应该通过引用传递警告:array_push()希望参数1是数组,在第29行的C:\xampp\htdocs\Lesson php\assignment\Location.php中给出的对象,它会这样说ohhso我该怎么做呢。如果答案是肯定的,请接受它作为答案注意:未定义索引:C:\xampp\htdocs\Lesson php\assignment\adminMenu.php中的全名,第89行