Blogger Information
Blog 250
fans 3
comment 0
visits 321734
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
MYSQL数据写入表格(实例)
梁凯达的博客
Original
1093 people have browsed it

实例

<?php

	//1.连接数据库
	$link =mysqli_connect('localhost','root','123456');


	//2.判断错误
	if (mysqli_connect_errno($link)>0) {
		echo  mysqli_connect_error($link);exit;
	}

	//3.选择数据库
	mysqli_select_db($link,'ss34');


	//4.设置字符集
	mysqli_set_charset($link,'utf8');

	//5.准备一条sql语句
	
	$sql="SELECT id,name,sex,age,city FROM info";

	//6.发送sql语句
	$result = mysqli_query($link,$sql);

	//7.处理结果集
	if($result && mysqli_num_rows($result)>0){
		echo '<table border ="1" width="800" align="center">';
		echo '<tr>';
		echo '<td>编号</td>';
		echo '<td>姓名</td>';
		echo '<td>年龄</td>';
		echo '<td>性别</td>';
		echo '<td>城市</td>';
		echo '</tr>';
		while($row = mysqli_fetch_assoc($result)){
			echo '<tr>';
			echo '<td>'.$row['id'].'</td>';
			echo '<td>'.$row['name'].'</td>';
			echo '<td>'.$row['age'].'</td>';
			echo '<td>'.$row['sex'].'</td>';
			echo '<td>'.$row['city'].'</td>';
			echo '</tr>';
	
		}
		echo '</table>';
	}

	mysqli_close($link);

运行实例 »

点击 "运行实例" 按钮查看在线实例

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post