100分求PHP无ID则读取全部数据

来源:百度知道 编辑:UC知道 时间:2024/06/22 03:20:12
这段代码在实际应用中可以用http://xxx.com/abc.php?id=1 (则读取栏目1的内容),我希望能够无ID的情况下,如http://xxx.com/abc.php则读取所有栏目的内容,该如何实现?具体要修改下面那个位置?
回答的好的加满100分
function newsclass($num,$Sorting,$Sequence)
{
global $db,$page,$classid,$intPerpage,$execc,$upfile,$webdir;
$intPerpage=$num;
if (isset($page)) {
$offset = ($page -1)*$num;
}
else {
$offset = 0;
}
$execc="SELECT id FROM news WHERE classname =$classid";
$strSql="SELECT id,classname,title,hits,Actor,photo,rec,hot,ser,content,addtime FROM news WHERE classname =$classid";
switch ($Sorting){
case 1:
$strSql.=" Order by id";
break;
case 2:
$strSql.=" Order by addtime";
break;
case 3:
$strSql.=" Order by hits

通过修改SQL语句的条件来实现你的需求:

function newsclass($num,$Sorting,$Sequence)
{
global $db,$page,$classid,$intPerpage,$execc,$upfile,$webdir;
$intPerpage=$num;
if (isset($page)) {
$offset = ($page -1)*$num;
}
else {
$offset = 0;
}
//////////////////////////////////////////////////////////////////////
if(strlen($classid)>0)
{
//如果id不为空
$execc="SELECT id FROM news WHERE classname =$classid";
$strSql="SELECT id,classname,title,hits,Actor,photo,rec,hot,ser,content,addtime FROM news WHERE classname =$classid";
}else{
//如果id为空
$execc="SELECT id FROM news";
$strSql="SELECT id,classname,title,hits,Actor,photo,rec,hot,ser,content,addtime FROM news";
}
//////////////////////////////////////////////////////////////////////
switch ($Sorting){
case 1:
$strSql.=" Order by id";
break;
case 2: