Actually the problem is this: there is a table, there are 3 fields in it (id, main, sub), id is just an index, main is the user id, who invited, sub - who invited.
Ie this is a module for DLE for referrals. And I need to display a list in the admin panel (nameplate), for example, User1 invited user2,3,4,5, and User2 invited user 6,7,8.
It seems to me that a cycle in a cycle is not the best option, because if there are 10 people, each invited 10 friends, then these are 110 requests. And given that I still get the ID for the nickname and the number of his orders, it is already 310. A lot of truth.
$db->query("SELECT distinct main FROM `" . PREFIX . "_refferal` LIMIT 10"); $db2 = new db; $db3 = new db; while ($row = $db->get_row()) { if ($bgcolor == "lightgrey") { $bgcolor = "white"; } else { $bgcolor = "lightgrey"; } $db3->query("SELECT name,skidka FROM `" . PREFIX . "_users` WHERE user_id='$row[main]'"); $unf = $db3->get_row(); $db3->query("SELECT id FROM `" . PREFIX . "_zakaz` WHERE user='$row[main]' AND (status='input' OR status='input')"); $zk = $db3->num_rows(); echo "<table border=0 width=600 align=center> <tr ><td width=257 align=center bgcolor=$bgcolor><a href='?do=refferals&act=full&id=$row[main]'>$unf[name]</a> ($unf[skidka]%) Заказов : $zk</td> <td><table>"; $db2->query("SELECT * FROM `" . PREFIX . "_refferal` WHERE main='$row[main]'"); while ($row2 = $db2->get_row()) { $db3->query("SELECT name,skidka FROM `" . PREFIX . "_users` WHERE user_id='$row2[sub]'"); $unf = $db3->get_row(); $db3->query("SELECT id FROM `" . PREFIX . "_zakaz` WHERE user='$row2[sub]' AND (status='input' OR status='input')"); $zk = $db3->num_rows(); if ($bgcolor2 == "lightgreen") { $bgcolor2 = "white"; } else { $bgcolor2 = "lightgreen"; } echo "<tr bgcolor=$bgcolor2><td width=300><a href='?do=refferals&act=full&id=$row[main]'>$unf[name]<a/> ($unf[skidka]%) Заказов : $zk</td></tr>"; } echo "</table></td></tr></table>"; }