I wrote a module for the DLE admin with my clumsy handles) At the last stage, there was a problem with the cycle. He does not want to work when inserting the code. In the example below, the beginning and end of a piece of code with which the cycle works and without which it works is marked with comments.

$db->query("SELECT * FROM ".USERPREFIX."_orders"); while($row = $db->get_row()) { /* НАЧАЛО ЕРУНДЫ */ $user_id = $row['user_id']; $order_id = $row['order_id']; $db->query("SELECT name FROM ".USERPREFIX."_users WHERE user_id = '$user_id'"); $b = $db->get_row(); $db->query("SELECT * FROM ".USERPREFIX."_order WHERE id = '$order_id'"); $c = $db->get_row(); /* КОНЕЦ */ echo '<tr> <td>'.$b['name'].'</td> <td>'.$c['title'].'</td> <td>'.$c['price_usd'].'</td> <td>'.$c['price_eur'].'</td> <td>'.$c['price_rub'].'</td> <td><a href="'.$module.'&end='.$row['id'].'">'.($row['is_end'] == 0 ? 'Нет': 'Да').'</a></td> <td><a href="'.$module.'&delete='.$row['id'].'"><img src="'.$config['http_home_url'].'engine/skins/images/delete.png" alt="Удалить" /></a></td> </tr>'; } 

As if everything is fine with this code, but the loop prints only one line from the database. Without it, it outputs as much as there is, but here is $ b, $ c, etc. does not work. Help me please!

    1 answer 1

    At first glance, the problem is this: by calling queries inside a loop, you wipe the result of the first query ( $db->query("SELECT * FROM ".USERPREFIX."_orders") ). Therefore, you first need to save the result of the first query to an array, and then walk through it by executing your code.

    • And if it’s not hard to imagine a piece of the table, and what do you want to get and present from it? Is it possible to find another way to solve with multiple cycles? - Ale_x
    • As a result, we must get the name of the user who ordered the product, the name of the product and its price (roughly speaking). orders - list of orders, there are indicated the user id and product id. On these id we look at the username in users and the name of the product with the price in order - inferusvv
    • Can I have a table schema with relationships? - Ale_x
    • Relational DBMS. The concept of relational (eng. Relation - relation). Roughly speaking, the connection tables through certain fields. Sorry, but such things need to know) - Ale_x
    • in general, the orders: id (A_I) user_id (user id), order_id (product id) columns. Well, the rest will not paint. Inquiries "bad piece" painted - inferusvv