<!DOCTYPE html>
<html>
<head>
<title>PHP 动态网站</title>
</head>
<body>
<?php
$user_name = 'shark';
echo "<h1>".$user_name."</h1>";
?>
<img src="/test.jpg" >
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>PHP 动态网站</title>
</head>
<body>
<h1>学员信息表</h1>
<table>
<thead>
<tr><th> 序号</th><th>姓名</th><th> 年龄</th></tr>
</thead>
<tbody>
<?php
define('DB_HOST', '172.17.0.2');
define('DB_USER', 'shark');
define('DB_PASS', 'QFedu123!');
define('DB_NAME', 'shark_db');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$query = "select id,name,age from t1 where name=%s;";
$result = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($result)) {
$user_id = $row['id'];
$user_name = $row['name'];
$user_age = $row['age'];
echo "<tr>";
echo "<td>".$user_id."</td>";
echo "<td>".$user_name."</td>";
echo "<td>".$user_age."</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</body>
</html>
在 php 语言中使用英文的
.
连接字符串和变量
echo "<h1>".DB_USER."</h1>"
,其中DB_USER
是使用define()
定义的变量。
网友评论