SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    limiting text length in dynamic drop down menu

    Hi i have a dropdown menu that i have linked to my mysql database. It displays beach names, some of which are very long. This means that the menu resizes to fit the longest name which messes up my page and looks poor. Is there a way of getting it to display eg the first 15 characters and then if the name is longer than that put ... after it. I assume this is done with php (if not sorry for posting in the wrong section). Your help will be much appreciated.

  2. #2
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    if you just want the first 15 characters without consideration of word breaks et al. you can use SQL:

    Code:
    SELECT CONCAT(LEFT(column,15), '...') FROM table;
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, thanks for the reply. Ive had a play around but it didn't seem to work with my page it just displayed a blank drop down. Iam using dreamweaver to do this. Heres the code ive been using if you have time to help some more.
    Code:
    <PHP?>
    mysql_select_db($database $gbg);
    $query_Recordset2 = "SELECT beach FROM content ORDER BY beach ASC";
    $Recordset2 = mysql_query($query_Recordset2, $gbg) or die(mysql_error());
    $row_Recordset2 = mysql_fetch_assoc($Recordset2);
    $totalRows_Recordset2 = mysql_num_rows($Recordset2);
    ?>
    And this is the dropdown
    Code:
                <form name="form2" method="get" action="result.php">
                  <div align="center"> 
                    <select name="beach" id="select2" onChange="document.all.form2.submit()";>
                      <option value="">Select Beach</option>
                      <?php
    do {  
    ?>
                      <option value="<?php echo $row_Recordset2['beach']?>"><?php echo $row_Recordset2['beach']?></option>
                      <?php
    } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
      $rows = mysql_num_rows($Recordset2);
      if($rows > 0) {
          mysql_data_seek($Recordset2, 0);
    	  $row_Recordset2 = mysql_fetch_assoc($Recordset2);
      }
    ?>
                    </select>
                  </div>
                </form>


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
  •