Issues with array counts



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...

function createDefaults($tableName,$userName,$configName,$dateModified)
{
$query="SELECT * FROM ".$tableName." WHERE id='0';";
$result = mysql_query($query);
if(!$result)
die("ERROR RETRIEVING DEFAULT DATA FROM '".$tableName."");
$dataArray = mysql_fetch_array($result);

$query="INSERT INTO ".$tableName." VALUES
('0','$userName','$configName','$dateModified'";
$colCount = sizeof($dataArray) / 2; <*************** this is where
it's returning double the column count, hence the / 2
for($count = 0; $count < $colCount - 4; $count++) // the -4 is a
standard set of columns put in each table
{
$query .= ",DEFAULT";
}
$query .= ");";
$result = mysql_query($query);
if(!$result)
die("ERROR SAVING DEFAULT DATA IN
'".$tableName."'<br>".mysql_error()."</p>");
}

Can anyone explain why?

Oh, if I do a print out of the array for each entry returned by sizeof(ie: 8
for 4 columns) it does say it's an empty or undefined index.

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?


.



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)