i have 3 tables customer class students…..
this is my table structure:
customer = customer_id, name, email
class = class_id, customer_id, classname
students = students_id, customer_id, firstname, image
customer table using for user login account
i had used the following query to get data from my students table under custmer_id
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "students WHERE
customer_id = '" . (int)$this->customer->getId() . "'");
foreach ($query->rows as $result) {
$students_data[$result['students_id']] = array(
'students_id' => $result['students_id'],
'class_id' => $result['class_id'],
'firstname' => $result['firstname'],
'image' => $result['image'],
);
}
but its look like no matter how many students i added inside my students table that all are returning each classroom. I had added 3 classes also inside my class table for example: class1 class2 class3, i want to display students who were added under class1 only, if i run class2 and class3, the same who the sames students are returned.
Can I get some help on how to properly query this?
From what I can see, I believe you need to connect your
studentstable to yourcustomerstable (or to your classes table, but it makes less sense). Then you can get your result using simple join something like…or something to that effect, after you add a
customer_idcolumn to your students table.