Home  >  Article  >  Backend Development  >  php调用mysql数据解决思路

php调用mysql数据解决思路

WBOY
WBOYOriginal
2016-06-13 13:12:19883browse

php调用mysql数据
有他个mysql数据库 a123456
里面有一个表 team
表里面有些字段: id,title,now_number

怎么用php调用6条mysql数据里的id,title等数据,按now_number的大小排序。


新手学习。先谢谢了。

------解决方案--------------------
...
$sql = 'SELECT * FROM team order by now_number desc limit 0,6';
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)){
echo "ID:".$row['id']." TT:".$row['title']."
";
}
------解决方案--------------------
....
$db = mysql_pconnect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());//链接数据库,参数分别为mysql的主机(localhost),用户名,密码
mysql_select_db('a123456') or die("Error conecting to db.");//选择数据库
$sql='select * from team order by now_number desc limit 0,6';
$result =mysql_query ($sql);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$id=$row["id"];
$title=$row["title"];
....

Statement:
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