| 
	
 | 
 Posted by Jerry Stuckle on 05/20/06 16:38 
aqazi@inbox.com wrote: 
> Hi guys I am having a problem with arrayu manipulation. 
>  
> in my php script i am reading from a csv file. 
> the content of file is like this: 
>  
> name,color,quantity,price; 
> apple,red,10,$2; 
> mango,green,12,$2.5; 
> orange,orange,8,$1.5; 
>  
> I am reading the file like this: 
>  
>   $userFile = fopen("data/user.csv", "r"); 
>   $data = array(); 
>   $record = array(); 
>  
>   while (($record = fgetcsv($userFile, 1000, ",")) !== FALSE) 
>   { 
>     array_push($data,$record); 
>   } 
>   fclose($userFile); 
>  
> Now if I want to change the quantity of mango what I have to do. I am 
> trying to do something, like this but it's not entirly correct. 
>  
>   foreach($data as $value) 
>   { 
>  
>     if(((strcasecmp("mango", $value[0]) == 0)) 
>     { 
>       echo $value[1].NL; 
>       $data[$value][1] = "1";* 
>       echo $data[$value][0].NL; 
>     } 
>   } 
>  
> Can anyone give me a hint how can I change the value here. 
>  
> Any help will be grealty appreciated. 
>  
> Thanks  
> aqazi 
>  
 
Two things: 
 
   The quantity is in $value[2], not $value[1]. 
   $data[$value][1] is incorrect.  $value is a row in $data, not an index.  So  
just use $value. 
 
   $value[2] = "1"; 
 
should work (but will set the count to a string instead of an integer). 
 
 
--  
================== 
Remove the "x" from my email address 
Jerry Stuckle 
JDS Computer Training Corp. 
jstucklex@attglobal.net 
==================
 
  
Navigation:
[Reply to this message] 
 |