very simple drop-down list...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • max

    very simple drop-down list...

    Hi! I'm having a problem with a very simple drop-down list since the
    page comes out with no elements in the drop-down but giving no errors.
    This is the code:


    <form name="year_sear ch_form" method="post" action="results .php">
    <select name="select_ye ar" id="select_year ">
    <?
    $query="SELECT * FROM table ORDER BY year";
    $result = mysql_query($qu ery) or die ("Error in query: $query. "
    ..mysql_error() );

    while ($line = mysql_fetch_arr ay($result)) {
    print ("<OPTION value=".$line['year']."></OPTION>"); }
    ?>
    </select>
    </form>

    The connection with the DB is established and working..
    Thanks for your help!!
  • Steve

    #2
    Re: very simple drop-down list...

    [color=blue]
    > <form name="year_sear ch_form" method="post" action="results .php">
    > <select name="select_ye ar" id="select_year ">
    > <?
    > $query="SELECT * FROM table ORDER BY year";
    > $result = mysql_query($qu ery) or die ("Error in query: $query. "
    > .mysql_error()) ;[/color]

    View the HTML source - any error message will be invisible via your
    browser because you are in the middle of specifying a form and dropdown
    list.

    ---
    Steve

    Comment

    • Geoff Berrow

      #3
      Re: very simple drop-down list...

      I noticed that Message-ID: <lomXe.7950$9l. 252465@twister1 .libero.it>
      from max contained the following:
      [color=blue]
      > print ("<OPTION value=".$line['year']."></OPTION>"); }[/color]

      Duh...
      print ("<OPTION>".$li ne['year']."</OPTION>"); }

      --
      Geoff Berrow (put thecat out to email)
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • max

        #4
        Re: very simple drop-down list...

        Steve probably wrote the following stuff on 19/09/2005 1.14:[color=blue][color=green]
        >><form name="year_sear ch_form" method="post" action="results .php">
        >><select name="select_ye ar" id="select_year ">
        >><?
        >>$query="SELEC T * FROM table ORDER BY year";
        >>$result = mysql_query($qu ery) or die ("Error in query: $query. "
        >>.mysql_error( ));[/color]
        >
        >
        > View the HTML source - any error message will be invisible via your
        > browser because you are in the middle of specifying a form and dropdown
        > list.[/color]

        ok, this is the html output source :

        <form name="year_sear ch_form" method="get" action="results .php">
        <select name="select_ye ar" id="select_year ">

        </select>
        <input name="submit" type="submit" class="search_b utton" value="Search">
        </form>

        it looks like it doesn't get anything...
        I tried a simple loop on the same page and it outputs the data fine...

        Comment

        • max

          #5
          Re: very simple drop-down list...

          Geoff Berrow probably wrote the following stuff on 19/09/2005 1.17:[color=blue]
          > I noticed that Message-ID: <lomXe.7950$9l. 252465@twister1 .libero.it>
          > from max contained the following:
          >
          >[color=green]
          >> print ("<OPTION value=".$line['year']."></OPTION>"); }[/color]
          >
          >
          > Duh...
          > print ("<OPTION>".$li ne['year']."</OPTION>"); }
          >[/color]

          tried as you said but still nothing...

          Comment

          • Darkstar 3D

            #6
            Re: very simple drop-down list...

            Please post a couple of lines of the html source in the problem area.
            Geoff's change looks spot on to me.

            Comment

            • Steve

              #7
              Re: very simple drop-down list...

              [color=blue]
              > <select name="select_ye ar" id="select_year ">
              >
              > </select>[/color]
              [color=blue]
              > it looks like it doesn't get anything...
              > I tried a simple loop on the same page and it outputs the data fine...[/color]


              Wait... print is not a function! Remove the parentheses, and try this:

              while ($line = mysql_fetch_arr ay($result))
              {
              print "<OPTION
              value=".$line['year'].">".$line['year']."</OPTION>";
              }

              ---
              Steve

              Comment

              • Darkstar 3D

                #8
                Re: very simple drop-down list...

                <---- Got plastered by that one!

                Comment

                • Geoff Berrow

                  #9
                  Re: very simple drop-down list...

                  I noticed that Message-ID:
                  <1127088877.010 943.86850@f14g2 000cwb.googlegr oups.com> from Steve
                  contained the following:
                  [color=blue]
                  >Wait... print is not a function! Remove the parentheses[/color]

                  True but that's not the problem. There are obviously no rows returned
                  by the query.

                  What I usually do is echo the SQL and paste it into phpMyadmin to check
                  the query.

                  --
                  Geoff Berrow (put thecat out to email)
                  It's only Usenet, no one dies.
                  My opinions, not the committee's, mine.
                  Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                  Comment

                  • David C.

                    #10
                    Re: very simple drop-down list...

                    Instead of:

                    <?
                    $query="SELECT * FROM table ORDER BY year";
                    $result = mysql_query($qu ery) or die ("Error in query: $query. "
                    ..mysql_error() );


                    while ($line = mysql_fetch_arr ay($result)) {
                    print ("<OPTION value=".$line['year']."></OPTION>"); }
                    ?>

                    Try this:

                    <?
                    $query="SELECT * FROM table ORDER BY year";
                    $result = mysql_query($qu ery) or die ("Error in query: $query. "
                    ..mysql_error() );
                    $num_rows = mysql_num_rows( $result);

                    for ($count = 0; $count < $num_rows; $count++) {
                    $line = mysql_fetch_arr ay($result);
                    print ("<OPTION
                    value=".$line['year'].">".$line['year']."</OPTION>"); }
                    ?>

                    Comment

                    • mars

                      #11
                      Re: very simple drop-down list...

                      Geoff Berrow probably wrote the following stuff on 19/09/2005 8.29:[color=blue]
                      > I noticed that Message-ID:
                      > <1127088877.010 943.86850@f14g2 000cwb.googlegr oups.com> from Steve
                      > contained the following:
                      >
                      >[color=green]
                      >>Wait... print is not a function! Remove the parentheses[/color]
                      >
                      >
                      > True but that's not the problem. There are obviously no rows returned
                      > by the query.
                      >
                      > What I usually do is echo the SQL and paste it into phpMyadmin to check
                      > the query.
                      >[/color]

                      thanks for your help guys, i tried to echo to output on the page without
                      using the "html select tag" and it works fine showing all the years..
                      But still it doesn't display anything in the dropdown menu.. :-\

                      Comment

                      • mars

                        #12
                        Re: very simple drop-down list...

                        Darkstar 3D probably wrote the following stuff on 19/09/2005 1.58:[color=blue]
                        > Please post a couple of lines of the html source in the problem area.
                        > Geoff's change looks spot on to me.
                        >[/color]

                        ok, well I put this:

                        <form name="year_sear ch_form" method="get" action="results .php">
                        <select name="select_ye ar" id="select_year ">
                        <?php
                        $num_rows = mysql_num_rows( $result);
                        for ($count = 0; $count < $num_rows; $count++) {
                        $line = mysql_fetch_arr ay($result);
                        print ("<OPTION value=".$line['year'].">".$line['year']."</OPTION>");}
                        ?>
                        </select>
                        <input name="submit" type="submit" class="search_b utton" value="Search">
                        </form>
                        ======
                        while just under it i displayed this to see if the sql query worked:
                        ======
                        <?php
                        $line = mysql_fetch_arr ay($result);
                        echo($line['year']);
                        while ($line = mysql_fetch_arr ay($result)) {
                        print ("<br>".$lin e['year']); }
                        ?>

                        and it outputs correctly the years contained in the table..
                        Thanks for your time!

                        Comment

                        • Steve

                          #13
                          Re: very simple drop-down list...


                          Yep quiet right, had no PHP to test with before, but now I do and this
                          makes no difference.

                          OP says he tried dumping the query results and got what he expected, so
                          must have used different queries in each case (or DB content has
                          changed.)

                          ---
                          Steve

                          Comment

                          • mars

                            #14
                            Re: very simple drop-down list...

                            max probably wrote the following stuff on 19/09/2005 1.04:[color=blue]
                            > Hi! I'm having a problem with a very simple drop-down list since the
                            > page comes out with no elements in the drop-down but giving no errors.
                            > This is the code:
                            >
                            >
                            > <form name="year_sear ch_form" method="post" action="results .php">
                            > <select name="select_ye ar" id="select_year ">
                            > <?
                            > $query="SELECT * FROM table ORDER BY year";
                            > $result = mysql_query($qu ery) or die ("Error in query: $query. "
                            > .mysql_error()) ;
                            >
                            > while ($line = mysql_fetch_arr ay($result)) {
                            > print ("<OPTION value=".$line['year']."></OPTION>"); }
                            > ?>
                            > </select>
                            > </form>
                            >
                            > The connection with the DB is established and working..
                            > Thanks for your help!![/color]


                            Fixed it! The main problem were the quotes :

                            print ('<OPTION value="'.$line['year'].'">'.$line['year'].'</OPTION>');

                            here it works.
                            Thanks!

                            Comment

                            • Geoff Berrow

                              #15
                              Re: very simple drop-down list...

                              I noticed that Message-ID: <IgAXe.8993$9l. 272957@twister1 .libero.it>
                              from mars contained the following:
                              [color=blue]
                              >Fixed it! The main problem were the quotes :
                              >
                              >print ('<OPTION value="'.$line['year'].'">'.$line['year'].'</OPTION>');[/color]

                              Personally I'd do it like this

                              print "<OPTION value='".$line['year']."'>".$line['year']."</OPTION>";
                              --
                              Geoff Berrow (put thecat out to email)
                              It's only Usenet, no one dies.
                              My opinions, not the committee's, mine.
                              Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                              Comment

                              Working...