A
A
alihang2018-04-27 12:14:26
PHP
alihang, 2018-04-27 12:14:26

How to separate array elements?

Hello, there is such a task:
Get a certain number of id (9 characters each) and compare them one by one with those stored in the database, if there is a match, then change the value in the database. For example, there are several id, 1,2,3, they need to be compared with those in the database. For example, there is a match with id number 2, and then you need to update the line in the database with this id.
To get data from the database I use the following code:

foreach ($likes_get ['response'] ['items'] as $likes) {
$r = $likes['id'];
$q = mysqli_query($db_connect, "SELECT id FROM `users` WHERE `id` = '$r'");
$rows = mysqli_fetch_assoc($q);

Next is the check:
if ($rows['id'] == $r) {
$query = mysqli_query($db_connect, "UPDATE `users` SET `likes_count` = '2' WHERE `id` = '$rows['id']'");
}

But either the check fails, or the request is not correct, but the data from the database does not change. If you try to display data from the rows array via echo, you get the following picture:
5ae2e87b3d957808868839.png
I think this is why the check does not pass. But if you try to use var_dump, then a normal array is output. I'm already completely confused. Can anyone suggest what exactly am I doing wrong?
PS Please do not throw slippers because in programming, and especially in php not long ago.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question