Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9118225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:05:43+00:00 2026-06-17T05:05:43+00:00

Currently I am using following code to get data sorted by starting letter of

  • 0

Currently I am using following code to get data sorted by starting letter of name, if you run this code you will get what i am trying to create

<?php 


$dirs = array('Aname1','Aname2','Aname3','A Nmae','Bname ','Cname','Cardiff','Dname','Dname',);
$cur_let = null;
foreach ($dirs as $dir) {
if ($cur_let !== strtoupper(substr($dir,0,1))){
$cur_let = strtoupper(substr($dir,0,1));
echo "<li class=\"title\">".$cur_let."</li>";
}

echo "<li class=\"clear\">



<div class=\"name\">".$dir."</div>
<div class=\"mobile\"></div>
<div  class=\"telephone\"></div>
<div  class=\"email\"></div>
<div  class=\"action\">edit | delete</div>



<div class=\"clear\"></div>


</li>";


} 

but how to use above loop inside following to get vales from database and it should be display like (I want highlight first letter) https://i.stack.imgur.com/bLHVD.jpg

$query = "SELECT * FROM phone_number"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
    $names =  $row['name'].",";

    }
    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:05:44+00:00Added an answer on June 17, 2026 at 5:05 am

    With MySQLi:

    $last_letter = null;
    
    $query = "SELECT name FROM phone_number ORDER BY name";
    $sql = $mysqli->query($query);
    while($row = $sql->fetch_assoc()) {
      $first_letter = substr(ucfirst($row['name']), 0, 1);
      if($last_letter != $first_letter) {
        $last_letter = $first_letter;
        echo '<div class="letter">', $first_letter, '</div>';
      }
    
      echo ucwords($row['name']), '<br />';
    
    }
    

    With mysql_* deprecated functions:

    $last_letter = null;
    
    $query = "SELECT name FROM phone_number ORDER BY name";
    $sql = mysql_query($query);
    while($row = mysql_fetch_array($sql)) {
      $first_letter = substr(ucfirst($row['name']), 0, 1);
      if($last_letter != $first_letter) {
        $last_letter = $first_letter;
        echo '<div class="letter">', $first_letter, '</div>';
      }
    
      echo ucwords($row['name']), '<br />';
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to seed some test data using the following code: #
I'm currently using the following PHP code: // Get all subordinates $subords = array();
I am currently using the following code to update form data before submission. $('.countyx').change(function(){
Currently for my blog I get a list of years/dates using the following code:
Currently i'm using the following code to get my custom MembershipUser, with my custom
I have currently got the following code which will run a bunch of ajax
Currently I am using the following code to print a large data structure print(json.dumps(data,
I am currently trying to drop a database via the following code using Microsoft.SqlServer.Management.Smo;
I am using following code to get current latitude and longitude. But none of
I want to get current alpha of textview i am using the following code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.