PHP Array

Discussion in 'PHP' started by simacaj, Nov 12, 2009.

  1. #1
    Hello -

    I am new to php and was wondering if I am going about effectively or is there an easier way to go about this.

    I have a multidimensional array created from some data I pulled out of mysql

    Example of the array

    array[0] = 12345, 1, 5
    array[1] = 56789, 2, 6
    array[2] = 09876, 3, 7

    The first numbers are product ids and the second and third are category ids.


    Here is how I extracted the values

    
    //While loop to spin through returned data
    while (($data = fgetcsv($handle, filesize($fileName), ",")) !== FALSE) {
    	
           //count fields in array
           $num = count($data);
    
    		for ($c=0; $c < $num; $c++) {
    			if ($c == 0)
    				{
                                    $productID = $data[$c];
    			}else {
    
    				$categoryID = $data[$c];
    			}
    }
    
    PHP:

    Is this an efficient way of getting these values or is there an easier way?

    Thanks
     
    simacaj, Nov 12, 2009 IP
  2. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't understand? You got data from a mysql table and saved it as comma separated values in a file? And then you read that file to get the values?
     
    CreativeClans, Nov 12, 2009 IP
  3. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #3
    you need not store data in file from mysql. simply read it from mysql using queries and if you are facing performance issue, then let us know table structure and queries you are using so that we can help you optimize them.
     
    mastermunj, Nov 12, 2009 IP