PHP输出数据库内容

<?php

 
	$con = mysqli_connect('localhost','root','123456','animal');
	if (!$con)
	{
		die('Could not connect: ' . mysqli_error($con));
	}
	
	mysqli_select_db($con,"endangeranimal");

	mysqli_set_charset($con, "utf8");
 

	$sql = "select id,name,province,city,number from location where name='大熊猫'";
	$result = mysqli_query($con,$sql);
 
	echo "<table border='1'>
	<tr>
	<th>ID</th>
	<th>动物名</th>
	<th>省份</th>
	<th>城市</th>
	<th>数量</th>
	</tr>";
 
	while($row = mysqli_fetch_array($result))
	{
		echo "<tr>";
		echo "<td>" . $row['id'] . "</td>";
		echo "<td>" . $row['name'] . "</td>";
		echo "<td>" . $row['province'] . "</td>";
		echo "<td>" . $row['city'] . "</td>";
		echo "<td>" . $row['number'] . "</td>";
		echo "</tr>";
	}
	echo "</table>";
 
	mysqli_close($con);
	
?>

猜你喜欢

转载自blog.csdn.net/lee18254290736/article/details/79929254