现有用户名为root,密码为root的MYSQL数据库服务器,其中有个名为JWGL的数据库,如何使用PHP程序设计显示JWGL数据库中student表的前15条记录
------解决方案--------------------
mysql_connect('localhost', 'root', 'root') or die(mysql_error());
mysql_select_db('JWGL') or die(mysql_error());
$rs = mysql_query('select * from student limit 15') or die(mysql_error());
while($r = mysql_fetch_assoc($rs)) {
echo join(' ', $r) . '<br />';
}
------解决方案--------------------
mysql_connect('localhost', 'root', 'root') or die(mysql_error());
mysql_select_db('JWGL') or die(mysql_error());
//假设你的编号字段名为 id
$rs = mysql_query('select * from student order by id desc limit 15') or die(mysql_error());
while($r = mysql_fetch_assoc($rs)) {
echo join(' ', $r) . '<br />';
}
------解决方案--------------------
$mysql_server_name='localhost';
$mysql_username='root';
$mysql_password='root';
$mysql_database='JWGL';
$mysql_table='student';
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database) or die(mysql_error());
mysql_select_db($mysql_database,$conn);
$sql='SET NAMES UTF8';//if utf8
mysql_query($sql);
$queStr ='SELECT * FROM '.$mysql_table.' ORDER BY id ASC LIMIT 0,15';//if pri key id
$result=mysql_query($queStr);
while($row = mysql_fetch_array($result)){
echo $row[0]." ".$row[1]."<br />";//or $row["test_col"]
}
mysql_close($conn);
------解决方案--------------------
SELECT * FROM student limit 0,15