A beginner question, but I myself am missing something. There is a code:

for ($i = 0; $i < count($sub1_emailFrom); $i++) { $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 ($sub3_result as $sub3) { if (($sub3['phone'] == $sub1_emailFrom[$i]) || ($sub3['url'] == $sub1_emailFrom[$i])) { $query4 = mysql_query("UPDATE users SET money = ({$sub3['money']} - {$sub3['taxes']}) WHERE users.id = {$sub3['id']}"); echo "Обновление у юзера:" . $sub3['id'] . " баланс равен:" . $sub3['money'] . "<br/>"; } } } } } 

It is necessary to go through the for loop normally, but for some reason everything will loop, tell me where to change what the loop would work correctly. What I get by client id

values ​​with which I compare

  • What does it mean to loop everything? And what does it mean for you correctly? Show what the cycle shows now, and what you want to receive, so they will answer your question faster. - G.Denis
  • Now the execution of the code cycles until the time limit on the script is enabled. In the horse I get the output of the rows with the words ka changed the balance of the user. Ie, if the if condition is fulfilled, then we get a verification label on the screen. At the moment, the number of elements in $sub1_emailFrom 212 elements and gives this: - ASYOU
  • 3 different cycles is brilliant. - Yura Petrov
  • all when that studied - ASYOU
  • one
    For a complete understanding of your problem, describe the algorithm completely, and unloading from the database. (Not in the comments, but in the post itself) - G. Denis

1 answer 1

From such profound explanations it is difficult of course to understand what he needs, but I will try

 foreach ($sub1_emailFrom as $email) { $email = mysql_real_escape_string($email); $query = "SELECT users.id, users.money, 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 phones.phone = '$email' OR site.url = '$email'"; $res = mysql_query($query); $row = mysql_fetch_assoc($row); $money = $row['money'] - $row['taxes']; mysql_query("UPDATE users SET money = $money WHERE id = $row[id]"; echo "Обновление у юзера:" . $row['id'] . " баланс равен: $money <br/>"; } 
  • It seems to be thanks a lot. - ASYOU