php curl请求接口并获取数据的示例代码
349
2023-12-10
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
echo "<table border=1>n";
echo "<tr><td>姓名</td><td>职位</td></tr>n";
while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td>%s %s</td><td>%s</td></tr>n", $myrow[1], $myrow[2], $myrow[3]);
}
echo "</table>n";
?>
</body>
</html>
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
if ($myrow = mysql_fetch_array($result)) {
echo "<table border=1>n";
echo "<tr><td>姓名</td><td>住址</td></tr>n";
do {
printf("<tr><td>%s %s</td><td>%s</tr>n", $myrow["first"],
$myrow["last"], $myrow["address"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>n";
} else {
echo "对不起,没有找到记录!";
}
?>
</body>
</html>
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
if ($myrow = mysql_fetch_array($result)) {
do {
printf("<a href="http://www.gimoo.net/t/1409/%s?id=%s">%s %s</a><br>n",
$PATH_INFO, $myrow["id"], $myrow["first"], $myrow["last"]);
} while ($myrow = mysql_fetch_array($result));
} else {
echo "对不起,没有找到记录!";
}
?>
</body>
</html>
程序开始变得复杂了,所以我在这里面加了注释,来解释一下到底发生了什么。您可以用//加入单行注释,或者用/*和*/来括住大段的注释。
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
// display individual record
// 显示单条记录内容
if ($id) {
$result = mysql_query("SELECT * FROM employees WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
printf("名: %sn<br>", $myrow["first"]);
printf("姓: %sn<br>", $myrow["last"]);
printf("住址: %sn<br>", $myrow["address"]);
printf("职位: %sn<br>", $myrow["position"]);
} else {
// show employee list
// 显示员工列表
$result = mysql_query("SELECT * FROM employees",$db);
if ($myrow = mysql_fetch_array($result)) {
// display list if there are records to display
// 如果有记录,则显示列表
do {
printf("<a href="http://www.gimoo.net/t/1409/%s?id=%s">%s %s</a><br>n", $PATH_INFO,
$myrow["id"], $myrow["first"], $myrow["last"]);
} while ($myrow = mysql_fetch_array($result));
} else {
// no records to display
// 没有记录可显示
echo "对不起,没有找到记录!";
}
}
?>
</body>
</html>
<html>
<body>
<form method="post" action="<?php echo $PATH_INFO?>">
名:<input type="Text" name="first"><br>姓:<input type="Text" name="last"><br>住址:<input type="Text" name="address"><br>职位:<input type="Text" name="position"><br><input type="Submit" name="submit" value="输入信息">
</form>
</body>
</html>
#免责声明#
本站[绿夏技术导航]提供的一切软件、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络收集整理,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容。如果您喜欢该程序或内容,请支持正版,购买注册,得到更好的正版服务。我们非常重视版权问题,如有侵权请邮件[admin@lxwl520.com]与我们联系进行删除处理。敬请谅解!