您的位置:首页 > 数据库 > MySQL

mysql select语句

2015-08-07 09:24 525 查看
<?php
$con=mysql_connect("localhost","root","");
if(!$con){
die("连接失败".mysql_error);
}

mysql_select_db("school",$con);

//select语句用于从数据库中选取数据
$result=mysql_query("SELECT * FROM student");

//打印该表中所有数据
/*
while($row=mysql_fetch_array($result)){
echo $row['Name']." ".$row['Sex'];
echo "<br/>";
}
*/

//使用表格打印出该表中所有数据
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Sex</th>

</tr>";
while($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$row['ID']."</td>";
echo "<td>".$row['Name']."</td>";
echo "<td>".$row['Sex']."</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: