アルファベット順でブランドリストを作成する方法。
私はテーブルを持っています...
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'"
私はこれを行う方法について何か考えが必要です.... mysqlを使用したphpで
私が使った...これ
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]);
}
}
}
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]);
}
}
}
これとともに:
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]);
}
}
}
それが問題かどうかわかりません。試してみてください
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加