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 649439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:56:39+00:00 2026-05-13T21:56:39+00:00

I’m having an issue here, I am trying to get all the titles from

  • 0

I’m having an issue here, I am trying to get all the titles from my database and list them in alphabetial order with the first letter indicating where we are at, so to be more clear:

A:
 Animal
 Alex
B:
 Boo
C:
 Crap

Actually this is what I use, and it works perfect:

<?php

$conn = mysql_connect('localhost','user','pw') or die(mysql_error());
$db = mysql_select_db('dbname') or die(mysql_error());

$sql = "select * from games order by title";
$result = mysql_query($sql, $conn) or die(mysql_error());

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

$letter = strtoupper(substr($list['title'],0,1));

if ($letter != $prev_row) {
echo "<br><b><u>$letter</u></b><br>";
} 
echo '<li><a href="/play/id/' . $list['id'] . '/">'.$list['title'].'</a></li>';

$prev_row = $letter;
} // end while
?>

But I would like it so, when it reaches the end of my div, let’s say 400px height, it starts on a new column like:

A:                             C: 

Alien                         Crap

B:                             D:

Boo                           Dododododo

I am really clueless at the moment, so any help would be really aprreciated!

Thanks alot

  • 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-05-13T21:56:40+00:00Added an answer on May 13, 2026 at 9:56 pm

    As columns are not yet broadly supported in HTML you’ll have to count the lines printed and multiply them by your defined line height.

    <?php
    
    $conn = mysql_connect('localhost','user','pw') or die(mysql_error());
    $db = mysql_select_db('dbname') or die(mysql_error());
    
    $sql = "select * from games order by title";
    $result = mysql_query($sql, $conn) or die(mysql_error());
    echo "<div style='float:left;height:400px;width:150px;'>";
    $current_height = 0;
    $line_height = '12px'; // replace by your value
    
    while ($list = mysql_fetch_array($result)) {
    
    $letter = strtoupper(substr($list['title'],0,1));
    
    if ( $current_height >= (400 - 2 * (int) $line_height) ) {
    echo "</div><div style='float:left;height:400px;width:150px;'>";
    $current_height = 0;
    }
    if ($letter != $prev_row) {
    echo "<br><b><u>$letter</u></b><br>";
    $current_height += (int) $line_height;
    } 
    echo '<li><a href="/play/id/' . $list['id'] . '/">'.$list['title'].'</a></li>';
    $current_height += (int) $line_height;
    
    $prev_row = $letter;
    } // end while
    echo "</div>";
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to render a haml file in a javascript response like so:

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.