how can i know new row insert my mysql database using php? -


i have create chatbox using php.its smoothly works.but don't know when new message inserted mysql database.how can know that? i've tried below code.but return me new message.

$initialcounter = 0; $count_query = "select * `message` `receiver_id` = '$sender_id' , `sender_id` = '$rid' order `id` desc"; $count_query_res = $conn->query($count_query); $countmsg = $count_query_res->num_rows; $initialcounter += $countmsg; $msgcounter = $initialcounter + $countmsg; if($initialcounter<$msgcounter){ echo "new message";} 

after inserting database, mysqli should return number of affected rows can use know if theres new data inserted in database.

number stored in $mysqli->affected_rows

example:

<?php $c = new mysqli("server","username","password","database");  $c->query("insert table(column1,column2,column3) values('data','data','data')");  echo $c->affected_rows; // returns affected rows ?> 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -