php - Fetch Tables with Only One Record and One Table with Several Records -
i have prepared statement inner joins 7 tables , sends email of information gathered. each table can have 1 record per person except uploaded_files table can have many records 1 person.
everything works great except when there multiple records in uploaded_files table receive empty array error , email doesn't send. assuming need loop through loop find multiple records in uploaded_field table can't seem figure out.
so there can 1 of every variable except $file_id, $file_name, $file_type, $file_size, , $file_path
i have simplified code below every variable in every table doesn't overshadow actual issue. can provide.
if(!mysqli_connect_errno()) { if($stmt = $db_connect->prepare("select s.student_id, s.student_first_name, s.student_last_name, y.agency_id, y.user_email, y.agency_name, y.agency_rep_name, y.agency_phone, p.personal_id, p.english_name, p.gender, p.date_of_birth, p.fathers_name, p.fathers_email, p.fathers_date_of_birth, p.fathers_phone_number, p.fathers_occupation, p.mothers_name, p.mothers_email, p.mothers_date_of_birth, p.mothers_phone_number, p.mothers_occupation, p.address_1, p.address_2, p.city, p.province, p.country, p.postal_code, p.home_phone, p.mobile_phone, p.in_grade, p.starting_grade, p.medical_insurance, p.homestay_placement, e.emergency_id, e.emerg_first_name, e.emerg_last_name, e.emerg_email, e.emerg_relationship, e.emerg_home_phone, e.emerg_mobile_phone, e.emerg_address_1, e.emerg_address_2, e.emerg_postal_code, e.emerg_city, e.emerg_province, e.emerg_country, a.academic_id, a.school_choice_1, a.school_choice_2, a.school_choice_3, a.preferred_community, a.study_duration, a.needs_canadian_credits, a.arrival_date, a.final_school_date, a.departure_date, a.years_of_english, a.speaking_english, a.writing_english, a.subject_area_1, a.subject_area_2, a.subject_area_3, a.subject_area_4, a.subject_area_5, a.subject_area_6, a.required_courses, a.graduation_goals, a.education_goals, a.semester_start, a.legalization, m.aboutme_id, m.nationality, m.religion, m.language_at_home, m.siblings, m.how_many_siblings, m.lived_in_english_country, m.which_english_country, m.how_long_in_english_country, m.personality, m.family_preference, m.dietary_requirements, m.my_dietary_requirements, m.food_preference, m.fav_foods, m.least_fav_foods, m.reading_genre, m.social_media, m.additional_info, m.hobbies, m.play_instrument, m.which_instrument, m.like_sports, m.which_sports, m.belong_to_clubs, m.which_clubs, m.religious_service, m.prefer_religious_service, m.household_chores, m.have_curfew, m.weekday_curfew, m.weekend_curfew, m.expectations, m.been_away_from_family, m.concerns_about_canada, m.allergies_medical_disabilities, m.airport_pickup, f.file_id, f.file_name, f.file_type, f.file_size, f.file_path students s inner join agency y inner join personal_information p using(student_id) inner join emergency_information e using(student_id) inner join academic_information using(student_id) inner join aboutme_information m using(student_id) inner join uploaded_files f using(student_id) p.student_id , e.student_id , a.student_id , m.student_id , f.student_id = ? , y.agency_id = ?") or die('something went wrong')) { $stmt->bind_param('ii', $student_id, $agency_id); /* execute */ $stmt->execute(); /*store results*/ $stmt->store_result(); /* number of rows */ $num_of_rows = $stmt->num_rows; $stmt->bind_result($student_id, $student_first_name, $student_last_name, $agency_id, $user_email, $agency_name, $agency_rep_name, $agency_phone, $personal_id, $english_name, $gender, $date_of_birth, $fathers_name, $fathers_email, $fathers_date_of_birth, $fathers_phone_number, $fathers_occupation, $mothers_name, $mothers_email, $mothers_date_of_birth, $mothers_phone_number, $mothers_occupation, $address_1, $address_2, $city, $province, $country, $postal_code, $home_phone, $mobile_phone, $in_grade, $starting_grade, $medical_insurance, $homestay_placement, $emergency_id, $emerg_first_name, $emerg_last_name, $emerg_email, $emerg_relationship, $emerg_home_phone, $emerg_mobile_phone, $emerg_address_1, $emerg_address_2, $emerg_postal_code, $emerg_city, $emerg_province, $emerg_country, $academic_id, $school_choice_1, $school_choice_2, $school_choice_3, $preferred_community, $study_duration, $needs_canadian_credits, $arrival_date, $final_school_date, $departure_date, $years_of_english, $speaking_english, $writing_english, $subject_area_1, $subject_area_2, $subject_area_3, $subject_area_4, $subject_area_5, $subject_area_6, $required_courses, $graduation_goals, $education_goals, $semester_start, $legalization, $aboutme_id, $nationality, $religion, $language_at_home, $siblings, $how_many_siblings, $lived_in_english_country, $which_english_country, $how_long_in_english_country, $personality, $family_preference, $dietary_requirements, $my_dietary_requirements, $food_preference, $fav_foods, $least_fav_foods, $reading_genre, $social_media, $additional_info, $hobbies, $play_instrument, $which_instrument, $like_sports, $which_sports, $belong_to_clubs, $which_clubs, $religious_service, $prefer_religious_service, $household_chores, $have_curfew, $weekday_curfew, $weekend_curfew, $expectations, $been_away_from_family, $concerns_about_canada, $allergies_medical_disabilities, $airport_pickup, $file_id, $file_name, $file_type, $file_size, $file_path); if($stmt->num_rows !==1){ $error_msg['finalize_button'] = 'there no student found completed application.'; }//end if no rows found else{ while($stmt->fetch()){ $body .= '<li><span>'.$student_first_nam.'</span></li>'; $body .= '<li><span>'.$agency_name.'</span></li>'; $body .= '<li><span>'.$english_name.'</span></li>'; $body .= '<li><span>'.$emerg_first_name.'</span></li>'; $body .= '<li><span>'.$school_choice_1.'</span></li>'; $body .= '<li><span>'.$religion.'</span></li>'; $body .= '<li><span>'.$file_id.'</span></li>'; $body .= '<li><span>'.$file_name.'</span></li>'; $body .= '<li><span>'.$file_type.'</span></li>'; $body .= '<li><span>'.$file_size.'</span></li>'; $body .= '<li><span>'.$file_path.'</span></li>'; } } }
i feel on right track aint working. sorry novel wanted explain best could
there wrong query.
where p.student_id , e.student_id , a.student_id , m.student_id , f.student_id = ?
does not want do. mean is
where p.student_id = ? , e.student_id = ? , a.student_id = ? , m.student_id = ? , f.student_id = ?
however, don't need put fields in where
clause @ all, since joined tables using same criterion.
all students, agencies etc. repeated many times there associated file records, need keep in mind when displaying data.
Comments
Post a Comment