mysql_fetch_array... interesting

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

    #1

    mysql_fetch_array... interesting

    hi all

    this is probably another simple one, but the web doesnt seem to have an
    answer that I can find.


    Veeeery simple code. each row has 10 columns.

    require('db.php ');
    $query = "SELECT * FROM mytable";
    $result = mysql_query($qu ery);
    $numrows = mysql_num_rows( $result);

    for($x=0; $x<$numrows; $x++)
    $row_arrays[$x] = mysql_fetch_arr ay($result);

    //test row 1
    foreach($row_ar rays[1] as $count)
    print "$count<br> ";

    result for each print is the column number (0-9) and each id(0,a,1,b,2,c
    etc). But if I use mysql_fetch_arr ay($result, 'MSQL_ASSOC') as the docs
    say, I get the 'The result type should be either MYSQL_NUM, MYSQL_ASSOC or
    MYSQL_BOTH' error. No quotes, additional error about undefined constant. I
    figure using this would get the array including the id only and not include
    the number. Perhaps its the wrong assumption?

    thanks
  • Gabriele Farina *DarkBard*

    #2
    Re: mysql_fetch_arr ay... interesting

    Theo wrote:[color=blue]
    > hi all
    >
    > this is probably another simple one, but the web doesnt seem to have an
    > answer that I can find.
    >
    >
    > Veeeery simple code. each row has 10 columns.
    >
    > require('db.php ');
    > $query = "SELECT * FROM mytable";
    > $result = mysql_query($qu ery);
    > $numrows = mysql_num_rows( $result);
    >
    > for($x=0; $x<$numrows; $x++)
    > $row_arrays[$x] = mysql_fetch_arr ay($result);
    >
    > //test row 1
    > foreach($row_ar rays[1] as $count)
    > print "$count<br> ";
    >
    > result for each print is the column number (0-9) and each id(0,a,1,b,2,c
    > etc). But if I use mysql_fetch_arr ay($result, 'MSQL_ASSOC') as the docs
    > say, I get the 'The result type should be either MYSQL_NUM, MYSQL_ASSOC or
    > MYSQL_BOTH' error. No quotes, additional error about undefined constant. I
    > figure using this would get the array including the id only and not include
    > the number. Perhaps its the wrong assumption?
    >
    > thanks[/color]


    Hi,

    the second parameter of mysql_fetch_arr ay function must be an INTEGER.
    MYSQL_BOTH, MYSQL_NUM and MYSQL_ASSOC are contants and have to be
    specified without single or double quote.

    bye

    Comment

    • Theo

      #3
      Re: mysql_fetch_arr ay... interesting

      Gabriele Farina *DarkBard* <darkbard@exten ding-php.net> wrote in
      news:D1qed.7586 7$b5.3649335@ne ws3.tin.it:
      [color=blue]
      > Theo wrote:[color=green]
      >> hi all
      >>
      >> this is probably another simple one, but the web doesnt seem to have
      >> an answer that I can find.
      >>
      >>
      >> Veeeery simple code. each row has 10 columns.
      >>
      >> require('db.php ');
      >> $query = "SELECT * FROM mytable";
      >> $result = mysql_query($qu ery);
      >> $numrows = mysql_num_rows( $result);
      >>
      >> for($x=0; $x<$numrows; $x++)
      >> $row_arrays[$x] = mysql_fetch_arr ay($result);
      >>
      >> //test row 1
      >> foreach($row_ar rays[1] as $count)
      >> print "$count<br> ";
      >>
      >> result for each print is the column number (0-9) and each
      >> id(0,a,1,b,2,c etc). But if I use mysql_fetch_arr ay($result,
      >> 'MSQL_ASSOC') as the docs say, I get the 'The result type should be
      >> either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH' error. No quotes,
      >> additional error about undefined constant. I figure using this would
      >> get the array including the id only and not include the number.
      >> Perhaps its the wrong assumption?
      >>
      >> thanks[/color]
      >
      >
      > Hi,
      >
      > the second parameter of mysql_fetch_arr ay function must be an INTEGER.
      > MYSQL_BOTH, MYSQL_NUM and MYSQL_ASSOC are contants and have to be
      > specified without single or double quote.
      >
      > bye
      >[/color]

      Hi thanks, yes I tried that as well.

      but this morning (I always think better in the late mornings) I used
      mysql_fetch_ass oc instead and all is good.

      However, on the fetch_array method, when I used MYSQL_ASSOC alone (first
      way I tried it) I get the undefined constant error. Well ok not an error, a
      notice - "PHP Notice: Use of undefined constant MSQL_ASSOC - assumed
      'MSQL_ASSOC'"It looks like it doesnt know what this constant is, so its
      changing it to a string. Question is why its not identifying the constant.
      Academic now but I dont like it when simple functions dont work they way
      they are supposed to... just bugs me because I might need it later :-)

      cheers!

      Comment

      • Andy Hassall

        #4
        Re: mysql_fetch_arr ay... interesting

        On Sat, 23 Oct 2004 17:23:58 -0000, Theo <invalid@noemai l.com> wrote:
        [color=blue]
        > when I used MYSQL_ASSOC
        >Use of undefined constant MSQL_ASSOC[/color]

        Spot the difference...

        --
        Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
        <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

        Comment

        • Theo

          #5
          Re: mysql_fetch_arr ay... interesting

          Andy Hassall <andy@andyh.co. uk> wrote in
          news:k19ln09cvv 969tn2m0oc547n3 vjr13807v@4ax.c om:
          [color=blue]
          > On Sat, 23 Oct 2004 17:23:58 -0000, Theo <invalid@noemai l.com> wrote:
          >[color=green]
          >> when I used MYSQL_ASSOC
          >>Use of undefined constant MSQL_ASSOC[/color]
          >
          > Spot the difference...
          >[/color]


          That loud sound you hear is me going

          doh!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!

          I knew it was going to something stupid I did ;o)

          Comment

          Working...