Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8803133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:15:46+00:00 2026-06-14T01:15:46+00:00

I am doing a sql query but it is not returning any data from

  • 0

I am doing a sql query but it is not returning any data from the tables. I am not sure why, I have changed from INNER to LEFT but no luck. I have revised the query several times but i cant find an issue. Any thoughts of why I am not getting anything displayed?

TABLE STRUCTURE

TABLE CREATE QUERY

PHP

$query = ("SELECT  class.class_name, class.class_caption, class.class_credit_hours, class.class_description, faculty_fname, faculty_lname
            FROM class
            LEFT JOIN section 
            ON class.id = section.class_id
            LEFT JOIN faculty 
            ON faculty.id = section.faculty_id OR faculty.id = office_hours.faculty_id
            LEFT JOIN faculty_titles
            ON faculty_titles.faculty_id = faculty.id
            LEFT JOIN faculty_education
            ON faculty_education.faculty_id = faculty.id 
            LEFT JOIN major_class_br
            ON major_class_br.class_id = class.id
            LEFT JOIN major_minor 
            ON major_class_br.major_minor_id = major_minor.id
            LEFT JOIN sched_sect_br 
            ON sched_sect_br.section_id =  section.id
            LEFT JOIN schedule
            ON schedule.id = sched_sect_br.schedule_id
            LEFT JOIN semester
            ON semester.id = schedule.semester_id
            LEFT JOIN office_hours
            ON schedule.id = office_hours.schedule_id AND faculty.id = office_hours.faculty_id       
                 ");
      //execute query
      $result = mysql_query($query);

     if ($result){

    $totalhours = 0;

    while ($row = mysql_fetch_assoc( $result ))
    {  
        print "<b>" . $row['class_name'] . "</b><br>";
        print $row['class_caption'] . "<br>";
        print $row ['class_credit_hours'] . "hrs. <br>";
            print $row ['faculty_lname'] . "hrs. <br>";
            print $row ['faculty_fname'] . "hrs. <br>";
        print $row['class_description'] . "<br>";      
        print "------------------------------<br />";
        $totalhours += $row['class_credit_hours']; 
    }   
    }

    print "<p>Total hours for Major: " . $totalhours . ".</p>";

Desired display:

Computer Programming I
CP1000
4
James Doe
This course offers introduction to programming. 

UPDATE: The issue was found here but I am not sure why

ON faculty.id = section.faculty_id OR faculty.id = office_hours.faculty_id
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:15:47+00:00Added an answer on June 14, 2026 at 1:15 am
    • Copy the SQL, go to MySQL admin, execute the SQL there and see if it returns any results.

    • Remove all the JOIN and execute again, you should see at least something

    • Add the JOIN one by one

    • Try to identify which JOIN resulted in no rows being returned

    • Check the left and right hand side of that join and ensure there actually are valid data to join

    Alternatively use OUTER JOIN

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have executed with no problem the query in SQL but it does not
I need to write following query in Linq to SQL but not sure what
When doing a SQL Query and I want to pull up entries from a
I have a problem with a query that works in phpmyadmin but not with
i have following sql query, everything works fine but when i put and posted_date<>$datetime
I try to bind a NSString value into my SQL query but its not
Not exactly sure what to call this, but in SQL I often find myself
I have SQL query like SELECT *, dbo.func(@param1, a.point) as fValue FROM dbo.table AS
I'm doing a linq-to-sql query and I wish the LastOrDefault operator were available but
Are they less vulnerable to SQL injection than doing stuff like mysql_query(SELECT important_data FROM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.