SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating Alphabetical links to records

    Hi guys,

    I am building a directory of company addresses. I want to be able to allow users to select links from a list of alphabets, where the alphabet represents the first first letter of the name they are looking for. This link will direct them to a list of companies with name starting with the alphabet clicked.

    Here is my code:

    Code:
    mysql_select_db($database_directory, $directory);
    $query_mda = "SELECT name FROM company ORDER BY name ASC";
    $mda = mysql_query($query_mda, $directory) or die(mysql_error());
    $row_mda = mysql_fetch_assoc($mda);
    $totalRows_mda = mysql_num_rows($mda);
    Thanks for your help

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    266
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Try use this select:
    Code:
    $name = 'the_name';
    $first_in_name = $name{0};
    $query_mda = "SELECT name FROM company WHERE SUBSTRING(name, 0, 1)='$first_in_name' ORDER BY name ASC";
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •