Re: Issues with array counts



427SOHC wrote:
In article <0NUmg.5431$1g.1061@xxxxxxxxxxxxxxxxxxxx>, PSI_Orion
says...

I have a table set up which has 4 columns. However, when I use the
sizeof() function on the array, it always returns DOUBLE the number
of columns. Here is an extract of my code...

Can anyone explain why?
if you check the mysql_fetch_array() function at php.net, the first
"contributed notes" talks about the scenario you described. From my
understanding mysql_fetch_array returns two arrays, the scalar and
associative arrays, so that doubles your count.

If you switch to the mysql_fetch_assoc function that should return
back a single array to give you a more accurate count, without have
to rig your code to divide by 2. : )

Or mysql_fetch_row() if you;re only using the numerical one.

One side note, where I'm doing a lot of testing and I'm using auto
increment on the ID field, how can I restet the values so it starts
from, lets say, 2 instead of 50?

ALTER TABLE `tablename` AUTO_INCREMENT = 2

Grtz,
--
Rik Wasmus


.



Relevant Pages

  • Re: A couple of things from H&S
    ... expression of array type decays to a pointer to the array's first ... element *unless* it's in one of three contexts: the operand of sizeof, ... is quite obvious, p is the pointer. ...
    (comp.lang.c)
  • Re: Null terminated strings: bad or good?
    ... specified type, it must not be possible to use callocto allocate such ... allocate such an array, that still doesn't make it possible for ... For any object that you can actually define in your program, with either static or automatic storage duration, "sizeof object" is supposed to give the size of that object; the standard provide no exceptions to this requirement. ...
    (comp.lang.c)
  • Re: C Strings
    ... sizeof ... More generally, given any array object, we can find a pointer to ... works quite as well for C99 as it did for C89, ...
    (comp.lang.c)
  • Re: Question about sizeof
    ... Mark double $$ ... This is true in any situation, not only with sizeof ... Cant you keep original values in the array instead of the variable names? ... -Each type of discography is associated with an array that contains ...
    (comp.lang.php)
  • Wording glitch: sizeof array vs. sizeof (array)
    ... A parenthesized expression is a primary expression. ... Except when it is the operand of the sizeof operator or the unary ... & operator, or is a string literal used to initialize an array, an ...
    (comp.std.c)