SELECT ABS(id-8),* FROM article ORDER BY 1 LIMIT 4
原理,使用id与指定值之差的绝对值作为排序项目,能按照接近程度查询数据,使用LIMIT限制结果数量。
SELECT id, name, (SELECT comment_id, title, content FROM B WHERE user_id = A.id ORDER BY create_time DESC LIMIT 1) FROM A您好,用递归的方法。<?php
global $str
$str = getson(0)//getson里面的参数是,上级目录的id
echo $str
function getson($fatherid)
{
$str = $str . "<ul>"
$sql="Select * From 表 Where 上级栏目ID=$fatherid"
$result = mysql_query($sql)
while ($row = mysql_fetch_array($result)) {
$str = $str . "<li>" . $row[栏目名称] . "</li>" . getson($row[该栏目的ID])
}
return $str."</ul>"
}
?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)