Welcome Guest, Not a member yet? Register   Sign In
Multidimensional arrays
#6

[eluser]Bogdan Tanase[/eluser]
As far as i know, mysql returns rows. So, even if you join the three tables, you'll only get back rows with multiple columns, corresponding to the joined tables.

So, maybe a way would be to create your array manually (like hvalente13 suggested).

Something like this:

//aprox code
Code:
//get client list in an array

$client_details_array=array(); //define the array to hold all the data

$client_list=$this->clients->GetList(); //define GetList in model clients (query DB for results)

foreach($client_list as $item)
{
  $client_details_array[]['name']=$item->name;
  $client_details_array[]['address']=$item->address;
  // ...
  
  //get client sites
  $client_details_array[]['client_sites']=$this->sites->GetListByClient($item->client_id);
  //get client contacts
  $client_details_array[]['client_contacts']=$this->contacts->GetListByClient($item->client_id);

}

in my example i assumed you have 3 models, one for each table.

The function GetList returns an array with the full content of clients table
The functions GetListByClient returns an array for tables sites and contacts only for the given client_id.

If you need more help with de models part i'll elaborate further.


Messages In This Thread
Multidimensional arrays - by El Forum - 07-18-2008, 08:20 AM
Multidimensional arrays - by El Forum - 07-18-2008, 08:47 AM
Multidimensional arrays - by El Forum - 07-18-2008, 08:58 AM
Multidimensional arrays - by El Forum - 07-18-2008, 09:00 AM
Multidimensional arrays - by El Forum - 07-18-2008, 09:18 AM
Multidimensional arrays - by El Forum - 07-18-2008, 10:40 AM
Multidimensional arrays - by El Forum - 07-18-2008, 01:02 PM
Multidimensional arrays - by El Forum - 07-18-2008, 01:43 PM
Multidimensional arrays - by El Forum - 07-18-2008, 01:50 PM
Multidimensional arrays - by El Forum - 07-18-2008, 09:33 PM



Theme © iAndrew 2016 - Forum software by © MyBB