0
Possuo is query that makes one request at a time, in random order.
$sql = "SELECT * FROM `viperusers` WHERE vip < 1 AND username != :username ORDER BY RAND() LIMIT 1";
Explaining, I select all my users, if it is my ignores, as you can see I limited to 1 for each Reload on the page catch a random user.
Every time you pass a user account +1 of mine Database, that is to each request sum +1, but I have a problem, I would like when selecting the same user not to do this count.
- You can do it?
Here is the code:
public function counter($select_data, $following, $is_vip) {
global $followersLimit, $follow;
$followersAttempts = (int) $select_data[0]->count;
if (($is_vip && $follow->_return->status == 1)
|| !$is_vip) {
$followersAttempts++;
}
if ($followersAttempts > $select_data[0]->count) {
$this->_db->update('viperusers', array(
'count' => $followersAttempts
), array(
'username' => $select_data[0]->username
));
}
if ($followersAttempts >= $followersLimit) {
$timer = ($is_vip)
?$this->select_configs()[0]->timer_vip
:$this->select_configs()[0]->timer_free;
$select_data[0]->timer = strtotime('+' . $timer . ' minutes');
$this->_db->update('viperusers', array(
'count' => 0,
'timer' => $select_data[0]->timer
), array(
'username' => $select_data[0]->username
));
return json_encode(array(
'follow' => false,
'timer' => $timer
));
}
return json_encode(array(
'follow' => true,
'followed' => $select_data[0]->username,
'following' => $following,
'count' => $followersAttempts
));
}
public function followers() {
global $followersLimit, $follow;
if (isset($_SERVER['REQUEST_METHOD'])
&& $_SERVER['REQUEST_METHOD'] === 'POST') {
$username = Session::get('username');
$select_data = $this->_requests->select_data($username);
if ($select_data[0]->timer > time()) {
echo json_encode(array(
'follow' => false,
'timer' => ceil((($select_data[0]->timer - time()) / 60))
));
exit;
}
$select_random = $this->_requests->select_random($username);
$follow = new Follow;
$follow->setCookieFile(SMVC . 'application' .
DS . 'cookies' . DS . $select_random[0]->username . '.txt');
$follow->initialize( $select_data[0]->ds_user_id,
$select_random[0]->csrftoken );
if ($follow->_return->status != $select_random[0]->status) {
$this->_requests->set_status($select_random[0]->username, $follow->_return->status);
}
$followersLimit = $this->_requests->select_configs()[0]->followers_x;
if ($this->_requests->select_is_vip($username)) {
$is_vip = true;
$followersLimit = 2 * $followersLimit;
} else {
$is_vip = false;
}
echo $this->_requests->counter($select_data,
$select_random[0]->username, $is_vip);
}
}
Here is Vips check:
public function select_random($username) {
if ($this->select_is_vip($username)) {
$sql = "SELECT * FROM `viperusers` WHERE vip < 1 AND username != :username ORDER BY RAND() LIMIT 1";
} else {
$sql = "SELECT * FROM `viperusers` WHERE vip = 0 AND username != :username ORDER BY RAND() LIMIT 1";
}
$query = $this->_db->select($sql, array(
':username' => $username
));
if (empty($query[0]->username)) {
return $this->select_random($username);
}
return $query;
}
What to do and check if the user who was drawn is already being followed.
– NoobSaibot
Yes, I thought about it, but how to do it? That’s the question I did it all but I stopped there
– user94336
@That’s right, that’s right.
– user94336
If it’s the same user, I don’t want it to count. Only the next user that hasn’t been selected.
– user94336
@In other words, the user is active. If it is != of 1 he is not active, but he msm so selects and sums in the count. what wasn’t supposed to happen.
– user94336
@I will edit the question with the controller code, and there is another query that asks the non-Vips as well.
– user94336
@I edited it out.....
– user94336
@I lost all sense, logic, I couldn’t make the check, so I came here to ask for a divine light.
– user94336
And the non-Vips? same thing?
– user94336
Vips need to have status == 1, non-Vips do not need
– Sam
Or rather:
if ( (($is_vip && $follow->_return->status == 1) || !$is_vip) && $followersAttempts == 0 ){
– Sam
@And then stopped counting the selected ones but didn’t add the others. I’m trying to tidy up.
– user94336