0

Can anyone help me on how to do thisalt text

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

2
  • Do you need an SQL statement? What exactly is it you're asking for? Commented Jan 15, 2011 at 11:23
  • 2
    You need to try and solve this problem yourself. If you encounter a specific problem/issue, then post a targeted question after first checking to see if another user hasn't already asked the same question. Commented Jan 15, 2011 at 11:23

2 Answers 2

1

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 :)

Sign up to request clarification or add additional context in comments.

1 Comment

the data is something like this Array ( [0] => Array ( [id] => 21 [name] => Wheel ) [1] => Array ( [id] => 22 [name] => Exterior ) [2] => Array ( [id] => 23 [name] => Interior ) [3] => Array ( [id] => 24 [name] => Brake ) [4] => Array ( [id] => 26 [name] => Lights ) )
0

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 >";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.