任何人都可以帮我解决如何执行此操作的问题
所有数据都应来自数据库,并按照上面显示的内容进行排列。谢谢..
答案 0 :(得分:1)
这些数据究竟是如何存储的?
您最终会按商家名称进行排序,每次出现新的第一个字符时,请将其打印为标题。
$get_businesses = mysql_query("SELECT * FROM businesses ORDER BY name ASC");
$last_character = '';
while($res_businesses = mysql_fetch_assoc($get_businesses))
{
$business_name = $res_businesses['name'];
$first_character = strtolower( sub_str($business_name, 0, 1) );
if($first_character !== $last_character){
print '<h1>'.strtoupper($first_character).'</h1>';
}
print '<p>'.$business_name.'</p>';
$last_character = $first_character;
}
如果是你的阵列
$last_character = '';
foreach($businesses as $business)
{
$business_name = $business['name'];
$first_character = strtolower( sub_str($business_name, 0, 1) );
if($first_character !== $last_character){
print '<h1>'.strtoupper($first_character).'</h1>';
}
print '<p>'.$business_name.'</p>';
$last_character = $first_character;
}
它最终未经测试,但希望它能为您提供所需的产品:)
答案 1 :(得分:0)
这是一个概念而不是完整的代码!
//连接数据库
$ sql =“SELECT * FROM ORDER BY DESC”;
$结果= mysql_query($ SQL);
而($行= mysql_fetch_array($结果)){
//在此处编写动态表格
echo“&lt; table&gt;&lt; td&gt;”;
if($ row ['name'] ==' Letter name ')//第一个字母然后转到新列&lt; br&gt;
}
echo“&lt; / table&gt;”;