| 
	
 | 
 Posted by 427SOHC on 06/24/06 00:23 
In article <0NUmg.5431$1g.1061@newsfe1-win.ntli.net>, 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... 
> 
>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?  
> 
> 
 
 
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. : ) 
 
 
--  
Newsguy Express 30 GB $9.95/month 
http://newsguy.com/overview.htm
 
  
Navigation:
[Reply to this message] 
 |