数据库IP为 localhost 端口为3306 用户名root 密码123456 数据库名为dbname 表名为tablename 字段名为 infoname
问题1 如何将 前五条内容 以id降序输出为
<li> 内容1 </li>
<li> 内容2 </li>
<li> 内容3 </li>
<li> 内容4 </li>
<li> 内容5 </li>
问题二 如何将 该字段所有内容都输出 并进行分页 每页3条
谢谢大家 纯属新手,希望大家 将代码一个字符不拉的 写一下!
第1个回答 推荐于2018-05-15
<?php
header("content-type:text/html;charset=utf-8");
$conn = mysql_connect('localhost','root','123456');
mysql_select_db('dbname',$conn);
mysql_query("set names utf8");
$sql = "select infoname from tablename limit 5 order by id desc";
$res = mysql_query($sql,$conn);
echo "<html>";
echo "<head>";
echo "</head>";
echo "<body>";
echo "<ul>";
while($row = mysql_fetch_assoc($res)){
echo "<li>".$row['infoname']."</li>";
}
echo "</ul>";
echo "</body>";
echo "</html>";
mysql_free_result($res);
mysql_close($conn);
?>本回答被提问者和网友采纳
header("content-type:text/html;charset=utf-8");
$conn = mysql_connect('localhost','root','123456');
mysql_select_db('dbname',$conn);
mysql_query("set names utf8");
$sql = "select infoname from tablename limit 5 order by id desc";
$res = mysql_query($sql,$conn);
echo "<html>";
echo "<head>";
echo "</head>";
echo "<body>";
echo "<ul>";
while($row = mysql_fetch_assoc($res)){
echo "<li>".$row['infoname']."</li>";
}
echo "</ul>";
echo "</body>";
echo "</html>";
mysql_free_result($res);
mysql_close($conn);
?>本回答被提问者和网友采纳
第2个回答 2014-01-03
我给你些个 SQL语句把 具体的MYSQL连接方式 查一下
select * from dbname limit 1, 5 order by id DESC
得到后循环输出
select * from dbname limit 1, 5 order by id DESC
得到后循环输出
第3个回答 2014-01-03
连接数据库都不会?
第4个回答 2014-01-03
<?php
$sql=mysql_query("select * from dbname order by tablename desc limit 5");
$row=mysql_fetch_object($sql);
do{
?>
<ul>
<li><?php echo $row->tablename; ?></li>
</ul>
<?php
}while($row=mysql_fetch_object($sql));
?>
$sql=mysql_query("select * from dbname order by tablename desc limit 5");
$row=mysql_fetch_object($sql);
do{
?>
<ul>
<li><?php echo $row->tablename; ?></li>
</ul>
<?php
}while($row=mysql_fetch_object($sql));
?>