php有很多连接mysql数据库的方法, 但是有时会各种失败, 记录一下能成功运行的模板
<?php
$mysql_server_name="localhost";
$mysql_username="root";
$mysql_password="1234";
$mysql_database="db";
$conn=new mysqli($mysql_server_name,$mysql_username,$mysql_password);
$conn->query("set names 'utf8'");
$conn -> select_db($mysql_database);
$njn = substr($_POST["id"],0,2);
$sql = "select * from info where id <> '{$_POST["id"]}'";
$result1 = $conn->query($sql);
$data=array();
echo "<tr class='info'>";
$num = 0;
if ($result1->num_rows > 0) {
while ($tmp=$result1->fetch_assoc())
{
if($num%7==0 and $num !=0){
echo "</tr><tr class='info_tr'>";
}
echo "<td><a href='index.php?id={$tmp["id"]}'> {$tmp['sname']} </a></td>";
$num += 1;
}
}else {
echo "未查询到";
}
echo "</tr>";
?>
网友评论