$ people = a multidimensional, associative array, which took values ​​from a query to the database

In general, there is a passage in the file and all sorts of names, surnames from the database, etc. are obtained. But I also need, inside the loop

<?foreach ($people as $scholar):?> 

I create another multidimensional array, I try to do it through the selectChild function. The problem is that in the array then lie the resources

  <?foreach ($people as $scholar):?> <?$child = selectChild($people);?> //Тут всякие вставки ... <?endforeach?> _______________________________________ ///Вот сама функция function selectChild($people){ $mass = array(); $children = array(); $children1 = array(); $children2 = array(); foreach ($people as $delete){ $id = $delete['children']; $id1 = $delete['children1']; $id2 = $delete['children2']; $delete['children'] != 0 ? $children = mysql_query("SELECT name, surname FROM datacenter WHERE id = '$id'") : $children = 0; $delete['children1'] != 0 ? $children1 = mysql_query("SELECT name, surname FROM datacenter WHERE id = '$id'") : $children = 0; $delete['children2'] != 0 ? $children2 = mysql_query("SELECT name, surname FROM datacenter WHERE id = '$id'") : $children = 0; $mass[] = array($children1, $children2); } return $mass; } 

    2 answers 2

    Well, cool:

     $delete['children'] != 0 ? $children = mysql_query("SELECT name, surname FROM datacenter WHERE id = '$id'") : $children = 0; 

    It is better:

     $children = $delete['children'] != 0 ? mysql_query("SELECT name, surname FROM datacenter WHERE id = '$id'") : 0; 

    And about the question: where is he?

      mysql_query returns a resource. need an array - handle the result of the request. In general, so to write it is a guard. As far as can be clear, you need to pull users out of the database. Is it really impossible to just pull everyone out? Even if not, then why send 3 requests in each iteration of the cycle, if you can send 1? Or if all the records are really not needed, then probably it is better to use the IN () operator and pull out all you need in one query, rather than fence such gardens.