Hoho, just learned, record it~
1. First create a new database, create a new data table test in it, and insert two records as shown in the picture

2. Create a new php file.
Code to connect to the database:
$conn=mysql_connect("localhost","root","");//連接數(shù)據(jù)庫(kù)服務(wù)器
if (!$conn){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mytest",$conn);//選擇數(shù)據(jù)庫(kù)mytetst
mysql_query("set names utf8");//設(shè)置編碼格式
mysql_connect(servername,username,password);
servername |
optional. Specifies the server to connect to. The default is "localhost:3306". |
username |
Optional. Specifies the username to log in with. The default value is the name of the user who owns the server process. |
password |
Optional. Specifies the password to use for login. The default is "". |
3. Execute database statements, such as query statements
$arr=mysql_query("select * from test",$conn);
Output query results
while($row = mysql_fetch_array($arr)){
echo $row['id'] . " " . $row['num'];
echo "<br />";
}
—————————————————————————— ——————————————
Implementation results:
When you click to find all, it displays:

When you search by id, enter 1 and it displays:

Complete code:
";
echo "
id | num | name | sex | bithday |
";
if(isset($_POST['select_all'])){
$arr=mysql_query("select * from test",$conn);
while($row = mysql_fetch_array($arr)){
echo "{$row['id'] } | {$row['num']} | {$row['name']} | {$row['sex']} | {$row['birthday']} |
";
// echo $row['id'] . " " . $row['num'];
// echo "
";
}
}else if (isset($_POST['select_sure'])) {
$id=$_POST['select_index'];
$arr=mysql_query("select * from test where id=$id",$conn);
if($row=mysql_fetch_assoc($arr)){
//如果查詢的到
echo "{$id} | {$row['num']} | {$row['name']} | {$row['sex']} | {$row['birthday']} |
";
}
}
echo "