This is example of my code wich get's information from two mysql tables, rather easy stuff.
One table contains realisations and the other got types for realisations. Correlation left join would be realisations.id = realisations_kind.realisation_id, my actual code, has no left join, i have been doing it just a dirty way.
$s = $mysqli->prepare( "SELECT id, name FROM realisations" );
$s->execute();
$s->bind_result( $id, $name );
$s->store_result();
while( $s->fetch())
{
/***/
$si = $mysqli->prepare( "SELECT kind FROM realisations_kind WHERE realisation_id = ?" );
$si->bind_param( 'i', $id );
$si->execute();
$si->bind_result( $kind );
$si->store_result();
while( $si->fetch())
{
if(isset($kind)) {
$arrayKind[] = $kind;
}
}
$return[] = array('id' => $id, 'name' => $name, 'kind' => $arrayKind);
$arrayKind = null;
/***/
}
This will output such array
Array
(
[0] => Array
(
[id] => 1
[name] => Building 1
[kind] => Array
(
[0] => 0
[1] => 1
)
)
[1] => Array
(
[id] => 2
[name] => Building 2
[kind] => Array
(
[0] => 1
)
)
..................more
so as you can see i got at index 0 key "kind" which got 2 results and at index 1 got "kind" 1 result, this is proper result because this table got 3 records two assigned to id1 and one to id2.
I have been trying to do this via left join and group sql statement but i can't find out how to do that, i did that several times in past but i forgot. Now i fill bit stupid to ask such basic thing there.
Left join results left table all rows result but duplicates right table or if i setup group by it remove duplicates from right but does not print out all results from left table, gives only first one :(