如何通过php

时间:2015-12-04 14:50:32

标签: php mysql

如何按字母顺序创建品牌列表。

我有一张桌子......

Brand     Brand_link   brand_photo  brand_alt

Adam       link1        photo1       alt1
Adiddas    link2        photo2       alt2
Foscrani   link3        photo3       alt3
Zumrani    link4        photo4       alt4
Kaboche    link5        photo5       alt5
Myur       link6        photo6       alt6   

现在我使用了这个查询...

SELECT SUBSTRING(brand_name, 1, 1) as brand,
brand_name,brand_country,brand_photo,brand_link,brand_id 
FROM brands
GROUP BY SUBSTRING(brand_name, 0, 2) , brand_name 
ORDER BY '$alpha','$brand_name'"

由此我得到了这个数组序列

enter image description here

但我想像这样创建我的品牌列表......

enter image description here

我需要知道如何做到这一点....在php with mysql

我用过......这个

foreach($results as $brand) { 
    $startsWith = strtolower($brand['brand']);

    if( array_key_exists($startsWith, $groups))
        array_push($groups[$startsWith], $brand);
    else 
    {
       foreach($results as $res){

           $groups[$startsWith] = Array($res[$startsWith]);

       }
    }
}

1 个答案:

答案 0 :(得分:1)

您忘记了SELECT * FROM ARBEITSBLOCK WHERE TO_CHAR(STARTZEIT,'DD.MM.YYYY H24:MM:SS') BETWEEN '30.11.2015 13:00:00' and '01.12.2015 19:05:00'; 声明

上的花括号

替换它:

if

有了这个:

foreach($results as $brand) { 
$startsWith = strtolower($brand['brand']);

if( array_key_exists($startsWith, $groups))
    array_push($groups[$startsWith], $brand);
else 
{
   foreach($results as $res){

       $groups[$startsWith] = Array($res[$startsWith]);

    }
  }
}

我不知道是否有问题请尝试