Home > Article > Backend Development > mysql - How to use php to get the data in the database and call it at the specified location in html and display it on the page (wamp environment)
There is an input in the html to display the data obtained by the backend
You also know how to obtain data from the database using php files
Currently I just don’t quite understand what the entire interaction process is~
There is an input in the html to display the data obtained by the backend
You also know how to obtain data from the database using php files
Currently I just don’t quite understand what the entire interaction process is~
If you use the framework, it will help you allocate the MVC corresponding to the address and then display it. Without using the framework, you can directly nest the back-end data request in an html page and fill it into the input
code:
<code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <center><table style="border:dotted;border-color:#F06"> <caption>留言内容</caption> <tr><th>编号</th><th>用户</th><th>标题</th><th>内容</th><th>发表时间</th></tr> <?php $link=mysql_connect('localhost','root','123')or die("数据库连接失败"); //连接数据库 mysql_select_db('lyb',$link);//选择数据库 mysql_query("set names utf8");//设置编码格式 $q="select * from content";//设置查询指令 $result=mysql_query($q);//执行查询 while($row=mysql_fetch_assoc($result))//将result结果集中查询结果取出一条 { echo"<tr><td>".$row["id"]."</td><td>".$row["username"]."</td><td>".$row["title"]."</td><td>".$row["content"]."</td><td>".$row["lastdate"]."</td><tr>"; } ?> </table> <a href="liuyanban.html">返回</a> </center> </body> </html></code>
First of all, according to our needs, there are two ways to achieve it!
1. As a newbie learning PHP backend in WAMP environment, let’s first look at the PHP+HTML hybrid implementation method:
<code><!Docutype html> <html lang="zh-CN"> <meta> <title>测试PHP+HTML混合</title> </meta> <body> <?php # 这一部分内容请您书写查询mysql数据库的过程 # 并将需要显示的值保存在变量 $fuck 中 # your code here.... ?> <input name="testvalue" value="<?php echo $fuck; ?>"> </body> </html> </code>
2. As a back-end PHP, we often need to integrate data into the front-end. After learning Javascript, we can use asynchronous interaction to obtain query results from the back-end and update them to the input
input field.
In projects, we usually use the latter method to achieve it.
If you need to know more, these keywords are for your reference:
Javascript
ajax
js asynchronous interaction
You can use the JQuery
library to experience a better Hack process of Javascript.