When sampling swears like this:

Object of class mysqli_result could not be converted to string ... on line 232

230-> echo"
231-> <div class='bo_pol'>
232-> <p><span class='otmetki'>".$com_pol."</span> | Полезность</p>
233-> </div>";

In addition to this line, the $ com_pol variable is used here:

209-> $com_pol = mysqli_query($link, "select sum(otzi_bal) as summ from comm_rate WHERE otzi_id='1'");

Actually because of the bottom line and an error occurs. In the sql query itself is executed correctly and gives the desired result. (I watched a similar topic Error object But I did not understand how to fix it) Thanks in advance.

    2 answers 2

     mysqli_query($link, "select sum(otzi_bal) as summ from comm_rate WHERE otzi_id='1'")->fetch_assoc()['summ']; 
    • I understood my mistake. This is really stupid as it happened. Thanks again. - Tahkolt

    From the description of mysqli_query

    Returns FALSE on failure. If the SELECT, SHOW, DESCRIBE, or EXPLAIN queries succeed, mysqli_query () will return a mysqli_result object. For other successful queries, mysqli_query () returns TRUE.

    You use SELECT . Then the correct code will be

     $res = mysqli_query( $link, "select sum(otzi_bal) as summ from comm_rate WHERE otzi_id='1'" ); if (!$res) die(mysqli_error($link)); $com_pol = $res->fetch_row()[0]; $res->close();