My SQL array and PHP

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

    #1

    My SQL array and PHP

    Hello
    I am new to PHP as well as arrays.
    I am using a select statement to obtain a table from mysql database. I
    want to store that table(with two columns Quesid, Numans) in an array
    which is sorted according to Numans.
    My table looks like this:
    Quesid Numans
    3 5
    2 3
    4 2
    1 2
    5 1
    Now I want to store first field of column Numans which is 5 into a
    variable, divide it by two and then parse through all the rows of the
    array and print that Quesid whcih is closest to 5/2. Once printed
    again go through the array with same condition and again print the
    next closest one.
    I would really appreciate a detailed answer. I am so stuck here.

    Thanks,
    Sunaina
  • David L

    #2
    Re: My SQL array and PHP

    how about rounding the result up (5/2=3), and if one is not found (or is
    the same), then minus one (3-1=2), and repeat.

    sunaina wrote:
    [color=blue]
    > Hello
    > I am new to PHP as well as arrays.
    > I am using a select statement to obtain a table from mysql database. I
    > want to store that table(with two columns Quesid, Numans) in an array
    > which is sorted according to Numans.
    > My table looks like this:
    > Quesid Numans
    > 3 5
    > 2 3
    > 4 2
    > 1 2
    > 5 1
    > Now I want to store first field of column Numans which is 5 into a
    > variable, divide it by two and then parse through all the rows of the
    > array and print that Quesid whcih is closest to 5/2. Once printed
    > again go through the array with same condition and again print the
    > next closest one.
    > I would really appreciate a detailed answer. I am so stuck here.
    >
    > Thanks,
    > Sunaina[/color]

    Comment

    • David L

      #3
      Re: My SQL array and PHP

      how about rounding the result up (5/2=3), and if one is not found (or is
      the same), then minus one (3-1=2), and repeat.

      sunaina wrote:
      [color=blue]
      > Hello
      > I am new to PHP as well as arrays.
      > I am using a select statement to obtain a table from mysql database. I
      > want to store that table(with two columns Quesid, Numans) in an array
      > which is sorted according to Numans.
      > My table looks like this:
      > Quesid Numans
      > 3 5
      > 2 3
      > 4 2
      > 1 2
      > 5 1
      > Now I want to store first field of column Numans which is 5 into a
      > variable, divide it by two and then parse through all the rows of the
      > array and print that Quesid whcih is closest to 5/2. Once printed
      > again go through the array with same condition and again print the
      > next closest one.
      > I would really appreciate a detailed answer. I am so stuck here.
      >
      > Thanks,
      > Sunaina[/color]

      Comment

      • sunaina

        #4
        Re: My SQL array and PHP

        David:
        Thank you very much for replying to my post. I had almost given up on
        this but now trying again to finish the program. I did use rounding
        earlier but did not think of repeating, using minus one, until your
        post. thanx for suggesting.

        David L <dl@nospam.co m> wrote in message news:<R11Kc.400 7$K53.1504@news-server.bigpond. net.au>...[color=blue]
        > how about rounding the result up (5/2=3), and if one is not found (or is
        > the same), then minus one (3-1=2), and repeat.
        >
        > sunaina wrote:
        >[color=green]
        > > Hello
        > > I am new to PHP as well as arrays.
        > > I am using a select statement to obtain a table from mysql database. I
        > > want to store that table(with two columns Quesid, Numans) in an array
        > > which is sorted according to Numans.
        > > My table looks like this:
        > > Quesid Numans
        > > 3 5
        > > 2 3
        > > 4 2
        > > 1 2
        > > 5 1
        > > Now I want to store first field of column Numans which is 5 into a
        > > variable, divide it by two and then parse through all the rows of the
        > > array and print that Quesid whcih is closest to 5/2. Once printed
        > > again go through the array with same condition and again print the
        > > next closest one.
        > > I would really appreciate a detailed answer. I am so stuck here.
        > >
        > > Thanks,
        > > Sunaina[/color][/color]

        Comment

        • sunaina

          #5
          Re: My SQL array and PHP

          David:
          Thank you very much for replying to my post. I had almost given up on
          this but now trying again to finish the program. I did use rounding
          earlier but did not think of repeating, using minus one, until your
          post. thanx for suggesting.

          David L <dl@nospam.co m> wrote in message news:<R11Kc.400 7$K53.1504@news-server.bigpond. net.au>...[color=blue]
          > how about rounding the result up (5/2=3), and if one is not found (or is
          > the same), then minus one (3-1=2), and repeat.
          >
          > sunaina wrote:
          >[color=green]
          > > Hello
          > > I am new to PHP as well as arrays.
          > > I am using a select statement to obtain a table from mysql database. I
          > > want to store that table(with two columns Quesid, Numans) in an array
          > > which is sorted according to Numans.
          > > My table looks like this:
          > > Quesid Numans
          > > 3 5
          > > 2 3
          > > 4 2
          > > 1 2
          > > 5 1
          > > Now I want to store first field of column Numans which is 5 into a
          > > variable, divide it by two and then parse through all the rows of the
          > > array and print that Quesid whcih is closest to 5/2. Once printed
          > > again go through the array with same condition and again print the
          > > next closest one.
          > > I would really appreciate a detailed answer. I am so stuck here.
          > >
          > > Thanks,
          > > Sunaina[/color][/color]

          Comment

          Working...