首先写一个提取品牌第一字母的函数 其实
这是最重要的
复制代码
第二步
结合我们的系统进行查询
复制代码
第三步 显示
- $dict=array(
- 'a'=>0xB0C4,
- 'b'=>0xB2C0,
- 'c'=>0xB4ED,
- 'd'=>0xB6E9,
- 'e'=>0xB7A1,
- 'f'=>0xB8C0,
- 'g'=>0xB9FD,
- 'h'=>0xBBF6,
- 'j'=>0xBFA5,
- 'k'=>0xC0AB,
- 'l'=>0xC2E7,
- 'm'=>0xC4C2,
- 'n'=>0xC5B5,
- 'o'=>0xC5BD,
- 'p'=>0xC6D9,
- 'q'=>0xC8BA,
- 'r'=>0xC8F5,
- 's'=>0xCBF9,
- 't'=>0xCDD9,
- 'w'=>0xCEF3,
- 'x'=>0xD188,
- 'y'=>0xD4D0,
- 'z'=>0xD7F9,
- );
- //取GB2312字符串首字母,原理是GBK汉字是按拼音顺序编码的.
- function get_letter($input)
- {
- global $dict;
- $str_1 = substr($input, 0, 1);
- if ($str_1 >= chr(0x81)
&& $str_1 <=
chr(0xfe)) {
- $num = hexdec(bin2hex(substr($input, 0,
2)));
- foreach ($dict as
$k=>$v){
- if($v>=$num)
- break;
- }
- return $k;
- }
- else{
- return $str_1;
- }
- }
-
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('brand').' order by brand_name'; -
$brand_array = $GLOBALS['db']->getall($sql); - $brand_list = array();
-
for($i=0;$i<count($brand_array);$i++)
- {
-
$brand_list[get_letter($brand_array[$i]['brand_name'])][$brand_array[$i]['brand_id']] = $brand_array[$i]['brand_name']."-".$brand_array[$i]['brand_id'];
-
- }
- 得到一个以第一字母为主键的数组
- foreach ($brand_list AS
$row=>$idx)
- {
-
-
$show .="<table width=\"766\" height=\"103\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"> -
<tr>
-
<td align=\"center\" style=\"border-right:1px solid #D0DFE8;border-bottom:1px solid #D0DFE8;border-left:1px solid #D0DFE8\"><table width=\"97%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> -
<tr> -
<td ><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> -
<tr> -
<td width=\"90%\" style=\"font-size:18px\"><strong><font color=\"#DC0000\">".$row."</font><a name=".$row." id=".$row."></a></strong></td>
-
<td style=\"font-size:14px\"><strong><a href=\"#top\" style=\"color: #0073CF;text-deocration:none\">Top</a></strong></td>
-
</tr> -
</table></td>
-
</tr>
-
<tr> -
<td style=\"line-height:200%\"> -
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> -
<tr>"; -
$a = 0; -
foreach($idx AS $row2=>$idx2) -
{ -
$a++; -
$idx2 = explode('-',$idx2); -
$show .= "<td align=\"left\"><span style=\"font-size:12px;\"><a href='brand.php?id=$idx2[1]' style=\"color:#00509f;text-decoration:none\">$idx2[0]</a></span></td>";
-
if($a%6 == 0) -
{ -
$show .="</tr><tr>";
-
} - }
-
$show .="</tr> -
</table>
-
</td>
-
</tr>
-
</table> -
</td>
-
</tr>
-
</table>";
- }
- $smarty->assign("show",$show);