Dropdown, formatting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jea
    New Member
    • Jan 2007
    • 11

    Dropdown, formatting

    First, sorry for poor English.
    I hav the following task:
    In a Mysql I have a table of events. An event is described in 3 fields: date, place, activity.
    Now I want to build a dropdown list where users can select one of the events by klicking, all in a wellknown manner.

    So far I have no problems, but the problem is that the text in the dropdown list is a mess. Two of the fields are of variable length.

    I tried a combination of adding spaces and then truncate with substr. It was a good improvement, but not good enough.
    Could anyone of you give me a hint to bring me inte the right track?

    Thanks in beforehand
    Jan-Erik
    Sweden.
    ***************
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Please show your code so we can look at what you have done until now.

    Ronald :cool:

    Comment

    • jea
      New Member
      • Jan 2007
      • 11

      #3
      Originally posted by ronverdonk
      Please show your code so we can look at what you have done until now.

      Ronald :cool:
      Ronald: Do I dare to? :-)
      [php]
      < body>
      < ?php
      include "TJanslut.p hp";
      $query = ("SELECT evdate, evname,evplats FROM events") or die ( mysql_error() );
      $result=mysql_q uery($query);
      $num=mysql_num_ rows($result);
      ? >
      < form action="action" method="post">
      < select name="option">
      < ?php
      while ($row = mysql_fetch_arr ay($result)) {
      echo "<option value=\"$row[evdate]\">$row[evdate]$row[evname]$row[evplats]\n</option>";
      }
      ? >
      < /select>
      < input type="submit">
      < /form>
      < /body>[/php]

      Comment

      • kamill
        New Member
        • Dec 2006
        • 71

        #4
        i am unable to understand your problem....Can you describe more...Actually i am unable to understand your requirement...

        Comment

        • jea
          New Member
          • Jan 2007
          • 11

          #5
          Originally posted by kamill
          i am unable to understand your problem....Can you describe more...Actually i am unable to understand your requirement...
          The result from the above code looks like this:
          070107 Shopping London
          070108 Visiting Grandma Stockholm
          070109 Party Berlin

          I want it to look like this:
          070107 Shopping....... ...........Lond on
          070108 Visiting Grandma....Stoc kholm
          070109 Party.......... .............Be rlin

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by jea
            The result from the above code looks like this:
            070107 Shopping London
            070108 Visiting Grandma Stockholm
            070109 Party Berlin

            I want it to look like this:
            070107 Shopping....... ...........Lond on
            070108 Visiting Grandma....Stoc kholm
            070109 Party.......... .............Be rlin
            If you use a fixed width font, you can check the length of each value pair (e.g. Shopping,London ). Find the max. length and add 2 or 3 to leave a bit of space between values. Use this max. figure (+2/3) to determine the number of dots to add in between values. If you're using a variable length font, the problem becomes a bit more difficult (you'll probably still have alignment issues), so i suggest if you want to guarantee alignment, use a fixed-width font.

            Comment

            • lordspace
              New Member
              • Nov 2006
              • 10

              #7
              Hi,

              is that what you want ?

              [php]
              <?php

              $row['evdate'] = '070107';
              $row['evname'] = 'Shopping';
              $row['evplats'] = 'London';

              $max_dots = 30;
              $row['evname'] .= str_repeat('.', abs(strlen($row['evname']) - $max_dots));

              //echo "<option value=\"$row[evdate]\">$row[evdate]$row[evname]$row[evplats]\n</option>";
              printf("<option value=\"{$row['evdate']}\">{$row['evdate']} {$row['evname']}{$row['evplats']}</option>\n");
              ?>
              [/php]

              Result would be:

              <option value="070107"> 070107 Shopping....... ............... London</option>

              Svet

              Comment

              • jea
                New Member
                • Jan 2007
                • 11

                #8
                Thank you so very much, both of you!
                problems nicely solved with a combination of your advice.
                I used the code directly, adjusted to max 15 dots, and changed to font Courier.
                Also, I changed from dots to nbsp.
                Great!

                Comment

                • lordspace
                  New Member
                  • Nov 2006
                  • 10

                  #9
                  printf() is not needed, you may use echo().
                  Basically you need following code before the echo() function

                  [php]
                  $max_dots = 30;
                  $row['evname'] .= str_repeat('.', abs(strlen($row['evname']) - $max_dots));
                  [/php]

                  Comment

                  • jea
                    New Member
                    • Jan 2007
                    • 11

                    #10
                    A new question arrived:
                    I want to show 5 events i the list box, and tried width size='5' in the select tag.
                    But it does not function, is this a result of the technics used?

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #11
                      It is easier to control the width of the select box by using an inline style attribute, such as:
                      [html]<select name="make" style="width:30 0px;">[/html]
                      Ronald :cool:

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Originally posted by jea
                        A new question arrived:
                        I want to show 5 events i the list box, and tried width size='5' in the select tag.
                        But it does not function, is this a result of the technics used?
                        Use
                        Code:
                        <select size="5" ...>
                        That should display 5 items at once instead of a dropdown.

                        Comment

                        • jea
                          New Member
                          • Jan 2007
                          • 11

                          #13
                          Thanks a lot to all of you for this excellent support. When I woke up this morning I was this <=> good at PHPing, now I feel I'm this <============ > good.
                          Sorry you at first did not understand what I was asking for, but it is no easy task to express oneself in a foreign language. Try some Swedish!

                          Comment

                          Working...