从6个表中选择仅获得一个结果

时间:2015-11-03 10:28:54

标签: php join mysqli

我有大约6个表,我正在循环它们,结果是1结果它应该更多

在这里查看我的代码

$institute = $_POST['institute'];
$sections = $_POST['sections'];
$division = $_POST['division'];


$getSearch = $db->prepare("SELECT
a.name, a.phase, a.setNumber, a.email, a.sudImage, a.activity, a.id AS stud_id,
b.id, b.ins_name,
c.id, c.sec_name,
d.id, d.div_name,
e.id, e.std_id, e.sub_id, e.absence,
f.id, f.sub_name, f.subHour, f.level
FROM student_basic_info AS a
JOIN institutes AS b ON (a.institute = b.id)
CROSS JOIN ins_sections AS c ON (a.section = c.id)
CROSS JOIN ins_division AS d ON (a.division = d.id)
CROSS JOIN student_absence AS e ON (a.id = e.std_id)
CROSS JOIN ins_subjects AS f ON (e.sub_id = f.id)
WHERE a.institute =? AND a.section = ? AND a.division =?
GROUP BY a.id
");

$studSearch = array();
$getSearch->bind_param('iii', $institute, $sections, $division);
if ($getSearch->execute()) {
    $results = $getSearch->get_result();
    while ($vStud = mysqli_fetch_assoc($results)) {
        $studSearch[] = $vStud;
        var_dump($studSearch);
        ?>

var_dump

array (size=1)
  0 => 
    array (size=17)
      'name' => string 'الدفع النقدي' (length=23)
      'phase' => string 'ابتدائي' (length=14)
      'setNumber' => int 0
      'email' => string 'johnef' (length=6)
      'sudImage' => string '' (length=0)
      'activity' => int 0
      'stud_id' => int 7
      'id' => int 3
      'ins_name' => string 'معهد الفنون' (length=21)
      'sec_name' => string 'فنون مسرح' (length=17)
      'div_name' => string 'شعبة مرجانية 10' (length=26)
      'std_id' => int 7
      'sub_id' => int 3
      'absence' => string '' (length=0)
      'sub_name' => string 'فنون تطبيقية' (length=23)
      'subHour' => string '2' (length=1)
      'level' => string 'المستوي الأول' (length=25)

修改

SELECT a.name, a.phase, a.setNumber, a.email, a.sudImage, a.activity, 
      a.id AS stud_id, b.id, b.ins_name, c.id, c.sec_name, d.id, d.div_name,
      e.id, e.std_id, e.sub_id, e.absence, f.id, f.sub_name, f.subHour, f.level 
FROM student_basic_info AS a 
  JOIN institutes AS b ON (a.institute = b.id)
  CROSS JOIN ins_sections AS c ON (a.section = c.id) 
  CROSS JOIN ins_division AS d ON (a.division = d.id) 
  CROSS JOIN student_absence AS e ON (a.id = e.std_id) 
  CROSS JOIN ins_subjects AS f ON (e.sub_id = f.id) 
WHERE a.institute =1 AND a.section = 1 AND a.division =7 
GROUP BY a.id 

并且是的,我得到了相同的结果(1)记录了它应该是最后(6)或(7)的记录

0 个答案:

没有答案