I am creating an e-shop in PHP using Codeigniter framework but I am stacked, how to design the database. My idea is, that this e-shop will have a backend full of functions and settings (creating categories, colours, adding goods, filemenager functions, and many many more). But, every user has his/her own categories, own colours, own goods,... so perhaps nothing is in common between users. Users have unique u_ids. Should I add a user ID to every table that I am using ? I give you an example of what I am intenting to do:
public function add_type_by_e_id($data = array(), $e_id = 0) {
if (!is_numeric($e_id)) {
$e_id = 0;
}
if (is_array($data) && count($data) > 0) {
$data['e_id'] = $e_id;
$this->db->insert($this->types, $data);
return $this->db->insert_id();
}
return false;
}
public function get_all_types_by_e_id($e_id = 0) {
if (!is_numeric($e_id)) {
$e_id = 0;
}
$this->db->from($this->types);
$this->db->where('e_id', $e_id);
$this->db->order_by('type', 'ASC');
$query = $this->db->get();
$result = $query->result();
$query->free_result();
if (count($result) > 0) {
return $result;
}
return false;
}
public function get_type_by_t_id_e_id($t_id = 0, $e_id = 0) {
if (!is_numeric($e_id)) {
$e_id = 0;
}
if (is_numeric($t_id) && $t_id > 0) {
$this->db->from($this->types);
$this->db->where('t_id', $t_id);
$this->db->where('e_id', $e_id);
$query = $this->db->get();
$result = $query->result();
$query->free_result();
if (count($result) > 0) {
return $result[0];
}
}
return false;
}
(In fact, $e_id is the user identifier.) My question is, whether is this the best and simplest way. The idea for this "$e_id thing" is, that I am afraid, that if no $e_id in this condition will be present, some user (or maybe a bug in the application) can fetch the data of the other user.
Thank you and I am waiting for your questions, because I feel it is a little bit confusing. :)
Peter