Rumah > Artikel > pembangunan bahagian belakang > 求编程。解决方案
求编程。。。
现有用户名为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 /> <br /> mysql_connect('localhost', 'root', 'root') or die(mysql_error());<br /> mysql_select_db('JWGL') or die(mysql_error());<br /> //假设你的编号字段名为 id <br /> $rs = mysql_query('select * from student order by id desc limit 15') or die(mysql_error());<br /> while($r = mysql_fetch_assoc($rs)) {<br /> echo join(' ', $r) . '<br />';<br /> }<br /> <br />
<br /> $mysql_server_name='localhost';<br /> $mysql_username='root';<br /> $mysql_password='root';<br /> $mysql_database='JWGL';<br /> $mysql_table='student';<br /> $conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database) or die(mysql_error());<br /> mysql_select_db($mysql_database,$conn);<br /> $sql='SET NAMES UTF8';//if utf8<br /> mysql_query($sql);<br /> <br /> $queStr ='SELECT * FROM '.$mysql_table.' ORDER BY id ASC LIMIT 0,15';//if pri key id<br /> $result=mysql_query($queStr);<br /> while($row = mysql_fetch_array($result)){<br /> echo $row[0]." ".$row[1]."<br />";//or $row["test_col"]<br /> }<br /> mysql_close($conn);<br />