I am not sure if this is the correct site to post it but we’ll see.
So i am building an app where users subscribe to others and each user has 2 pages for Subscribers and Subscriptions to check his data.
I then added a Subscribe/Unsubscribe button in the Subscriptions page(must be logged in and be the owner of the subscriptions) next to each user that has subscribed to a user but this has to check to see if the logged in user has subscribed or not to show the proper button.
If for example i show 20 per page items i have to do 20 more SQL queries… with some other data that i require for the page to render it can go to 50 sql queries… is this normal or im using way to many Queries?
EDIT :
This is the function that i call to check if i have subscribed to any of my subscriptions to show the proper button
public function hasSubscribedTo($user_id){
$this->db->where('uid', $this->session->userdata['uid']);
$this->db->where('suid', $user_id);
$sql = $this->db->get($this->db->dbprefix('subscribers'));
return $sql->num_rows();
}
this is normal. But you can always have one query and then cache the data that expires in X number of seconds. and then read the cache instead. but with pagination or real time checking this stuff is normal.
You may also like to read about memcache.
Memcache module provides handy procedural and object oriented interface to memcached, highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications.