function getCataLog($catalog){
$catalog = "select name from commodity where catalog = ".$catalog." ORDER BY rank desc LIMIT 10";
$result = mysql_query($catalog);
 
while($row = mysql_fetch_assoc($result)){
     $response [] = $row;
}
}
改写成方法

解决方案 »

  1.   

    是这样调用吗  getCataLog(11);但没数据出来
      

  2.   

    function getCataLog($catalog){
        $catalog = "select name from commodity where catalog = ".$catalog." ORDER BY rank desc LIMIT 10";
        $result = mysql_query($catalog);
      
        while($row = mysql_fetch_assoc($result)){
             $response [] = $row;
        }
        return $response;
    }
      

  3.   

    还有个神奇的问题catalog = 11 数据库有3条记录
    catalog = 12 数据库有11条记录$responses = getCataLog(11) + getCataLog(12);这样输出应该是有14条记录的,但实标只输出了10条。而且catalog = 12的数据是从第四条开始接的
      

  4.   

    不是这么用的 php里面的 + 相比于数组的合并 array_merge 相同键值的被覆盖掉了
      

  5.   

    select name,catalog,rank from commodity c where 10 > (select count(*) from commodity where catalog=c.catalog and id>c.id) and catalog in (1,2,3,4,5,6,7,8,10,11) order by c.catalog,c.rank desc
      

  6.   

    function getCataLog($catalog,&$response = array()){
        $catalog = "select name from commodity where catalog = ".$catalog." ORDER BY rank desc LIMIT 10";
        $result = mysql_query($catalog);
      
        while($row = mysql_fetch_assoc($result)){
             $response [] = $row;
        }
    }
    $response = array();
    getCataLog(1,$response);
    var_dump($response);
    getCataLog(2,$response);
    var_dump($response);
      

  7.   


    请问再加两个条件怎么加啊,我这样加了,但这样加了和数据库对不上,少了很多条数据。
    $etId = $_GET['etId'];
    $cityId = $_GET['cityId'];"select name from commodity where catalog = 1 and cityId = $cityId and etId = $etId ORDER BY rank desc LIMIT 10""select name,catalog,rank from commodity c where 10 > (select count(*) from commodity where catalog=c.catalog and id>c.id) and catalog in (1,2,3,4,5,6,7,8,10,11) and cityId = $cityId and etId = $etId order by c.catalog,c.rank desc"