drop down not displaying all rows

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

    drop down not displaying all rows

    Hello, George and Toby helped me out with a scripted to populate a
    drop down box from a dynamic section:

    I am having an issue with the drop down box. If there is only one row
    in the table the drop down box will display nothing. once the table
    has two or more rows the drop down displays the row but always one shy
    of the total. here is the script i am using:

    $query = "SELECT SEC_TITLE
    FROM section
    WHERE SEC_TITLE != ''";

    $result = mysql_query($qu ery);

    while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC))

    { echo "<form action='#'>\r\n <select name=section>\r \n";
    while ($line = mysql_fetch_arr ay($result, MYSQL_NUM)) {
    $section = $line[0];
    echo " <option value=$section> $section\r\n";
    }
    }

    If anyone can help me get this drop down box to display all rows even
    if there is only one row, i would really appreciate it.

    Thanks

    God bless
    jason

  • =?ISO-8859-15?Q?Iv=E1n_S=E1nchez_Ortega?=

    #2
    Re: drop down not displaying all rows

    jsd219 wrote:
    I am having an issue with the drop down box. If there is only one row
    in the table the drop down box will display nothing. once the table
    has two or more rows the drop down displays the row but always one shy
    of the total. here is the script i am using:
    Why are you echo()ing the <formand the <select*insid e* the loop, again?

    --
    ----------------------------------
    Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

    Lo que es pecado de muchos queda sin castigo.- Marco Anneo Lucano.

    Comment

    • jsd219

      #3
      Re: drop down not displaying all rows

      On Jun 13, 5:30 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
      escomposlinux.-.punto.-.orgwrote:
      jsd219 wrote:
      I am having an issue with the drop down box. If there is only one row
      in the table the drop down box will display nothing. once the table
      has two or more rows the drop down displays the row but always one shy
      of the total. here is the script i am using:
      >
      Why are you echo()ing the <formand the <select*insid e* the loop, again?
      >
      --
      ----------------------------------
      Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
      >
      Lo que es pecado de muchos queda sin castigo.- Marco Anneo Lucano.
      The drop down box is dynamic. It will populate based on however many
      Sections have been created.

      Comment

      • =?ISO-8859-15?Q?Iv=E1n_S=E1nchez_Ortega?=

        #4
        Re: drop down not displaying all rows

        jsd219 wrote:
        >Why are you echo()ing the <formand the <select*insid e* the loop,
        >again?
        >
        The drop down box is dynamic. It will populate based on however many
        Sections have been created.
        I'm not asking why the <option>s are inside a loop. I'm asking why the
        <selectis inside a loop.

        --
        ----------------------------------
        Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-


        Proudly running Debian Linux with 2.6.20-1-amd64 kernel, KDE 3.5.7, and PHP
        5.2.3-1 generating this signature.
        Uptime: 01:37:14 up 13 days, 7:39, 3 users, load average: 0.30, 0.37,
        0.42

        Comment

        • jsd219

          #5
          Re: drop down not displaying all rows

          On Jun 13, 6:37 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
          escomposlinux.-.punto.-.orgwrote:
          jsd219 wrote:
          Why are you echo()ing the <formand the <select*insid e* the loop,
          again?
          >
          The drop down box is dynamic. It will populate based on however many
          Sections have been created.
          >
          I'm not asking why the <option>s are inside a loop. I'm asking why the
          <selectis inside a loop.
          >
          --
          ----------------------------------
          Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
          >

          Proudly running Debian Linux with 2.6.20-1-amd64 kernel, KDE 3.5.7, and PHP
          5.2.3-1 generating this signature.
          Uptime: 01:37:14 up 13 days, 7:39, 3 users, load average: 0.30, 0.37,
          0.42
          Honestly i am not sure, i am a newbie with php and one of the other
          guys on this board give my that sting to use. I only had to modify it
          a bit so i haven't questioned it much. unfortunately i am now having
          problems with it. I am trying to learn. If you could explain what is
          coded wrong and why i would really appreciate it

          God bless
          jason

          Comment

          • Norman Peelman

            #6
            Re: drop down not displaying all rows

            jsd219 wrote:
            Hello, George and Toby helped me out with a scripted to populate a
            drop down box from a dynamic section:
            >
            I am having an issue with the drop down box. If there is only one row
            in the table the drop down box will display nothing. once the table
            has two or more rows the drop down displays the row but always one shy
            of the total. here is the script i am using:
            >
            $query = "SELECT SEC_TITLE
            FROM section
            WHERE SEC_TITLE != ''";
            >
            $result = mysql_query($qu ery);
            >
            while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC))
            >
            { echo "<form action='#'>\r\n <select name=section>\r \n";
            while ($line = mysql_fetch_arr ay($result, MYSQL_NUM)) {
            $section = $line[0];
            echo " <option value=$section> $section\r\n";
            }
            }
            >
            If anyone can help me get this drop down box to display all rows even
            if there is only one row, i would really appreciate it.
            >
            Thanks
            >
            God bless
            jason
            >
            $query = "SELECT SEC_TITLE FROM section WHERE SEC_TITLE != ''";
            $result = mysql_query($qu ery);
            echo "<form action='#'>\r\n <select name='section'> \r\n";
            while ($row = mysql_fetch_arr ay($result, MYSQL_NUM))
            {
            echo " <option value='{$row[0]}'>$row[0]\r\n";
            }
            echo "</form>\r\n";


            Norm

            Comment

            • jsd219

              #7
              Re: drop down not displaying all rows

              On Jun 13, 11:13 pm, Norman Peelman <npeel...@cfl.r r.comwrote:
              jsd219 wrote:
              Hello, George and Toby helped me out with a scripted to populate a
              drop down box from a dynamic section:
              >
              I am having an issue with the drop down box. If there is only one row
              in the table the drop down box will display nothing. once the table
              has two or more rows the drop down displays the row but always one shy
              of the total. here is the script i am using:
              >
              $query = "SELECT SEC_TITLE
              FROM section
              WHERE SEC_TITLE != ''";
              >
              $result = mysql_query($qu ery);
              >
              while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC))
              >
              { echo "<form action='#'>\r\n <select name=section>\r \n";
              while ($line = mysql_fetch_arr ay($result, MYSQL_NUM)) {
              $section = $line[0];
              echo " <option value=$section> $section\r\n";
              }
              }
              >
              If anyone can help me get this drop down box to display all rows even
              if there is only one row, i would really appreciate it.
              >
              Thanks
              >
              God bless
              jason
              >
              $query = "SELECT SEC_TITLE FROM section WHERE SEC_TITLE != ''";
              $result = mysql_query($qu ery);
              echo "<form action='#'>\r\n <select name='section'> \r\n";
              while ($row = mysql_fetch_arr ay($result, MYSQL_NUM))
              {
              echo " <option value='{$row[0]}'>$row[0]\r\n";}
              >
              echo "</form>\r\n";
              >
              Norm
              Thank you :-)

              God bless
              jason

              Comment

              • =?ISO-8859-15?Q?Iv=E1n_S=E1nchez_Ortega?=

                #8
                Re: drop down not displaying all rows

                jsd219 wrote:
                Honestly i am not sure, i am a newbie with php and one of the other
                guys on this board give my that sting to use. I only had to modify it
                a bit so i haven't questioned it much. unfortunately i am now having
                problems with it. I am trying to learn. If you could explain what is
                coded wrong and why i would really appreciate it
                Well, I wanted you to think a bit instead of giving you the solution.

                See, a typical <selectis something like:

                <select ... >
                <option ...... </option>
                <option ...... </option>
                <option ...... </option>
                <option ...... </option>
                </select>

                So the code structure has to be something like:

                echo "<select ... >";
                while (whatever)
                {
                echo "<option ... ... </option>";
                }
                echo "</select>";


                In your case, you were doing something like:

                while (mysql_fetch_ar ray()
                {
                echo "<select ...>";

                while (mysql_fetch_ar ray())
                {
                echo "<option ... </option>";
                }
                }


                Your code was fetching a row, DO NOTHING WITH IT, echo the <select>, and
                then echo()ing the rest of the rows. Do you see the problem now?

                --
                ----------------------------------
                Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

                He hath eaten me out of house and home.
                -- William Shakespeare, "Henry IV"

                Comment

                • jsd219

                  #9
                  Re: drop down not displaying all rows

                  On Jun 14, 7:31 am, Iván Sánchez Ortega <ivansanchez-...@rroba-
                  escomposlinux.-.punto.-.orgwrote:
                  jsd219 wrote:
                  Honestly i am not sure, i am a newbie with php and one of the other
                  guys on this board give my that sting to use. I only had to modify it
                  a bit so i haven't questioned it much. unfortunately i am now having
                  problems with it. I am trying to learn. If you could explain what is
                  coded wrong and why i would really appreciate it
                  >
                  Well, I wanted you to think a bit instead of giving you the solution.
                  >
                  See, a typical <selectis something like:
                  >
                  <select ... >
                  <option ...... </option>
                  <option ...... </option>
                  <option ...... </option>
                  <option ...... </option>
                  </select>
                  >
                  So the code structure has to be something like:
                  >
                  echo "<select ... >";
                  while (whatever)
                  {
                  echo "<option ... ... </option>";}
                  >
                  echo "</select>";
                  >
                  In your case, you were doing something like:
                  >
                  while (mysql_fetch_ar ray()
                  {
                  echo "<select ...>";
                  >
                  while (mysql_fetch_ar ray())
                  {
                  echo "<option ... </option>";
                  }
                  >
                  }
                  >
                  Your code was fetching a row, DO NOTHING WITH IT, echo the <select>, and
                  then echo()ing the rest of the rows. Do you see the problem now?
                  >
                  --
                  ----------------------------------
                  Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
                  >
                  He hath eaten me out of house and home.
                  -- William Shakespeare, "Henry IV"

                  I am starting to get it now. Thanks, by the way below is the working
                  code. :-)

                  God bless
                  jason

                  $query = "SELECT SEC_TITLE
                  FROM section
                  WHERE SEC_TITLE != ''";

                  $result = mysql_query($qu ery);

                  echo "<form action='#'>\r\n <select name='section'> \r\n";
                  while ($row = mysql_fetch_arr ay($result, MYSQL_NUM))
                  {
                  echo " <option value='{$sectio n[0]}'>$row[0]\r\n";

                  }

                  Comment

                  Working...