There are 4 tables interconnected by id hierarchically users-> phones-> sites-> tax and there is an incoming data array in which there is a column of the form
site.ru
site2.ru
site3.ru
123456
8967654
456876
Each user also has a cash account column. How to make a request that would go through the incoming array and, if the data from the column with attached data matches, each user (phone number or website) withdrew the tax clogged in the tax table (the tax is linked only to the site). I can’t think of such a search with simultaneous comparison and updating of account data. If you have clarifying questions ask may have given an incomplete picture.
Here is what happened as a result:

 $query2 = mysql_query("SELECT id FROM users WHERE id NOT IN (1,2)"); while ($sub_money2 = mysql_fetch_array($query2)) { $query3 = mysql_query("SELECT users.id, users.money, phones.phone, site.url, rates.taxes FROM users LEFT JOIN phones ON users.id = phones.user_id LEFT JOIN site ON phones.id = site.phones_id LEFT JOIN rates ON site.id = rates.site_id WHERE users.id = {$sub_money2['id']}"); while ($sub_money3 = mysql_fetch_array($query3)) { $sub3_result[] = $sub_money3; foreach ($sub1_emailFrom as $sub1) { foreach ($sub3_result as $sub3) { if (($sub3['phone'] == $sub1) || ($sub3['url'] == $sub1)) { $query4 = mysql_query("UPDATE users SET money = ({$sub3['money']} - {$sub3['taxes']}) WHERE users.id = {$sub3['id']}"); echo "Обновление у юзера:" . $sub3['id'] . " баланс равен:" . $sub3['money'] . "<br/>"; } } } } } 

There remains only the question of how to do it so that after each successful IF (tobish when the funds were removed from the balance, the balance was updated and in the future the funds were removed from the new balance immediately every time there is a withdrawal from the initial amount)

  • one
    First, make an ordinary select which selects data from these tables. It is necessary to repel something. Therefore, to this select, add a bundle of conditions as if you were checking suitable records (for one value) something like "site.ru" in(table_a.site, table_b.phone,...) . And then convert it to update .... - Mike
  • when the data from the column with associated data matches each user (phone number or website), the tax collected in the tax table was removed from his account (the tax is linked only to the website). The tax is tied only to the site, and shoot it for the site and for the phone? - Akina
  • to do so after each successful IF (tobish when the funds were withdrawn from the balance, the balance was updated and in the following funds were withdrawn from the new balance immediately every time the initial amount is withdrawn. That is, do you keep and constantly recalculate the current status of his account in the user data table? As one politician said, “There are no words to express myself!” ... it seems to be not accepted here, but on many resources, having seen this, they begin to recommend changing jobs. - Akina
  • The essence of it in this was what it was. The withdrawal normally takes place both for the site and for the phone. The question is how to make sure that after each withdrawal the balance is updated and removed further from the new balance. - ASYOU

0