Home > Backend Development > PHP Tutorial > 求编程。解决方案

求编程。解决方案

WBOY
Release: 2016-06-13 13:03:54
Original
920 people have browsed it

求编程。。。
     现有用户名为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 />
Copy after login

------解决方案--------------------
<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 />
Copy after login

------解决方案--------------------
SELECT * FROM student limit 0,15

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template