$query_up = "UPDATE `" . $res_str . "` SET Hostname = '$data[1]', Ports = '$data[2]', Mac_address = '$data[3]', Mac_vendor = '$data[4]', date = '" . date('Ymd H:i') . "' WHERE IP = '$data[0]'"; $resaddnet = mysqli_query($GLOBALS['link'], $query_up); printf("Затронутые строки (UPDATE): %d\n", mysqli_affected_rows($GLOBALS['link'])); 

As a result, always displays 1, how to make the number of updated lines displayed?

  • one
    So you seem to be doing everything right. Can it really always update on 1 line? - Mike
  • it happens that several connections to the database are opened and then confused in the code, maybe it is - Eugene Bartosh

1 answer 1

You have everything right in the request and in the return of the affected lines. All about it here .

In your query, the conditional WHERE statement takes ip - a very unique record. Accordingly, only one line undergoes changes.

And the number of updated lines, for example, for a session or for another period, you better keep separately, in the same $ _session:

 session_start(); /*... a lot of useful code ...*/ if($rows = mysqli_affected_rows($GLOBALS['link'])): $_session['aff_rows'] += $rows; endif; 
  • (In your query, the conditional WHERE statement takes ip — a very unique record.) If the IP is a unique field, then yes, but not the fact. - azhirov1991
  • @ azhirov1991 You are right, if there is a base of addresses from different subnets, ip will not be unique. We assume that the questioner works with one) - Kirill Korushkin