100分求PHP无ID则读取全部数据
这段代码在实际应用中可以用http://xxx.com/abc.php?id=1(则读取栏目1的内容),我希望能够无ID的情况下,如http://xxx.com/abc....
这段代码在实际应用中可以用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";
break;
}
switch ($Sequence){
case 1:
$strSql.=" desc";
break;
case 2:
$strSql.=" asc";
break;
}
$strSql.=" limit $offset,$num";
$db->query($strSql);
$movie_array = array();
$i=0;
while($db->next_record())
{
$movie_array[] = array(
'title' => $db->Record["title"],
'classname' => namezh("news_class","classname",$db->Record["classname"]),
'classurl' => newsclasslink($db->Record["classname"]),
'regionurl' => regionlink($db->Record["regionname"]),
'actor' => str_replace("|"," ",$db->Record["Actor"]),
'pic' => pic($db->Record["photo"]),
'content' => $db->Record["content"],
'date' => substr($db->Record["addtime"],0,10),
'hits' => $db->Record["hits"],
'num' => $i+=1,
'url' => newslink($db->Record["id"],$db->Record["addtime"])
);
}
return $movie_array;
unset($movie_array);
} 展开
回答的好的加满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";
break;
}
switch ($Sequence){
case 1:
$strSql.=" desc";
break;
case 2:
$strSql.=" asc";
break;
}
$strSql.=" limit $offset,$num";
$db->query($strSql);
$movie_array = array();
$i=0;
while($db->next_record())
{
$movie_array[] = array(
'title' => $db->Record["title"],
'classname' => namezh("news_class","classname",$db->Record["classname"]),
'classurl' => newsclasslink($db->Record["classname"]),
'regionurl' => regionlink($db->Record["regionname"]),
'actor' => str_replace("|"," ",$db->Record["Actor"]),
'pic' => pic($db->Record["photo"]),
'content' => $db->Record["content"],
'date' => substr($db->Record["addtime"],0,10),
'hits' => $db->Record["hits"],
'num' => $i+=1,
'url' => newslink($db->Record["id"],$db->Record["addtime"])
);
}
return $movie_array;
unset($movie_array);
} 展开
1个回答
展开全部
通过修改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:
$strSql.=" Order by addtime";
break;
case 3:
$strSql.=" Order by hits";
break;
}
switch ($Sequence){
case 1:
$strSql.=" desc";
break;
case 2:
$strSql.=" asc";
break;
}
$strSql.=" limit $offset,$num";
$db->query($strSql);
$movie_array = array();
$i=0;
while($db->next_record())
{
$movie_array[] = array(
'title' => $db->Record["title"],
'classname' => namezh("news_class","classname",$db->Record["classname"]),
'classurl' => newsclasslink($db->Record["classname"]),
'regionurl' => regionlink($db->Record["regionname"]),
'actor' => str_replace("|"," ",$db->Record["Actor"]),
'pic' => pic($db->Record["photo"]),
'content' => $db->Record["content"],
'date' => substr($db->Record["addtime"],0,10),
'hits' => $db->Record["hits"],
'num' => $i+=1,
'url' => newslink($db->Record["id"],$db->Record["addtime"])
);
}
return $movie_array;
unset($movie_array);
}
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:
$strSql.=" Order by addtime";
break;
case 3:
$strSql.=" Order by hits";
break;
}
switch ($Sequence){
case 1:
$strSql.=" desc";
break;
case 2:
$strSql.=" asc";
break;
}
$strSql.=" limit $offset,$num";
$db->query($strSql);
$movie_array = array();
$i=0;
while($db->next_record())
{
$movie_array[] = array(
'title' => $db->Record["title"],
'classname' => namezh("news_class","classname",$db->Record["classname"]),
'classurl' => newsclasslink($db->Record["classname"]),
'regionurl' => regionlink($db->Record["regionname"]),
'actor' => str_replace("|"," ",$db->Record["Actor"]),
'pic' => pic($db->Record["photo"]),
'content' => $db->Record["content"],
'date' => substr($db->Record["addtime"],0,10),
'hits' => $db->Record["hits"],
'num' => $i+=1,
'url' => newslink($db->Record["id"],$db->Record["addtime"])
);
}
return $movie_array;
unset($movie_array);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询