开发者

PHP Mysql Data Arrangement

开发者 https://www.devze.com 2023-02-05 07:18 出处:网络
Ca开发者_运维问答n anyone help me on how to do this All the data should come from database and arrange like what has show above.Thanks..How is this data stored, exactly?

Ca开发者_运维问答n anyone help me on how to do this

PHP Mysql Data Arrangement

All the data should come from database and arrange like what has show above.Thanks..


How is this data stored, exactly?

You would ultimately order by the business name and every time a new first character came up, print that as a title.

$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;
}

If it's from your array

$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;
}

It's ultimately untested but hopefully it'll give you what you need :)


This is a concept not the full code !

//connect to database

$sql="SELECT * FROM ORDER BY DESC";

$result=mysql_query($sql);

while($row=mysql_fetch_array($result)){

//write a dynamic table here

echo "< table > < td >";

if($row['name'] == 'Letter name') //the first letter then go to a new column < br >

}

echo "< /table >";

0

精彩评论

暂无评论...
验证码 换一张
取 消