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

  • SEARCH
  • Home
  • 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 8881989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:27:55+00:00 2026-06-14T20:27:55+00:00

HI all i have an issue echoing out my data. I have three tables,

  • 0

HI all i have an issue echoing out my data.
I have three tables, one for students, classes and student_classes.
I’ve queried the db to joint the all three so i can see all students, whether they have enrolled in a class or not with their class. the sql is

SELECT students.id, students.student_name, students.student_number,
section_student.ss_id, section_student.section_number,sections.subject 
FROM students 
LEFT JOIN student_classes
ON students.student_number=student_classes.student_number 
LEFT JOIN classes 
ON classes.class_number=student_classes.class_number 
WHERE students.status=1

This produces a list of students with classes if they have them. for those students who have enrolled in more than one course there name shows twice in the list.

When i print_r the data i get

Array
(
[0] => stdClass Object
    (
        [class_number] => 
        [student_name] => john smith
        [student_number] => 432100351
        [id] => 2
        [ss_id] => 
        [subject] => 
        [user_email] => john@email.com
        [created_at] => 0000-00-00 00:00:00
        [updated_at] => 0000-00-00 00:00:00
    )

[1] => stdClass Object
    (
        [class_number] => 43223
        [student_name] => Paul jones
        [student_number] => 432100312
        [id] => 3
        [ss_id] => 40
        [subject] => Maths
        [user_email] => Paul@email.com
        [created_at] => 0000-00-00 00:00:00
        [updated_at] => 2012-11-24 08:33:23
    )

[2] => stdClass Object
    (
        [class_number] => 21331
        [student_name] => Paul jones
        [student_number] => 432100312
        [id] => 3
        [ss_id] => 39
        [subject] => Physics
        [user_email] => Paul@email.com
        [created_at] => 0000-00-00 00:00:00
        [updated_at] => 2012-11-24 08:33:23
    )

When i do a for each in a table to show the students and their class I want to loop through the classes that a student has in one line. eg

john ID:432100351 | N/A
Paul ID:432100312 | 43223 = Maths , 21331 = Physics

When i do my loops i get

ID:432100351 john | john@email.com | N/A
ID:432100312 Paul | paul@email.com | 43223 = Maths , 21331 = Physics
ID:432100312 Paul | paul@email.com | 43223 = Maths , 21331 = Physics

Im not sure if the problem is with my sql or my loop

Here is the code

@foreach ($students as $student)
<tr>
<td> {{ $key++ }}</td>
<td> {{ HTML::link('students/edit/' .$student->id, $student->student_number) }} </td>
<td> {{ HTML::link('students/edit/' .$student->id, $student->student_name) }} </td>
<td> {{ $student->user_email }} </td>
<td>


    @if(!isset($student->ss_id)) 

        {{ HTML::link('add_student_section.php?student_id='.$student->id,'Add to section'); }}

    @else 

        @foreach($students as $section) 

         {{ HTML::link('edit_student_section.php?ss_id=', $section->section_number . " " . $section->subject . " ") ;}}     

        @endforeach

    @endif    

</td>
<td> {{ date("d-M-Y H:i",strtotime($student->created_at )) }} </td>
<td> 
@if($student->updated_at == $student->created_at)

N/A

@else

{{ date("d-M-Y H:i",strtotime($student->updated_at )) }} 
@endif

</td>
<td> {{ HTML::link('students/delete/' .$student->id, 'Delete Student') }} </td>
</tr>
@endforeach

Any help would be appreciated. Thanks

  • 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-14T20:27:57+00:00Added an answer on June 14, 2026 at 8:27 pm

    You need to use GROUP BY in conjunction with GROUP_CONCAT

    SELECT students.id, students.student_name, students.student_number,GROUP_CONCAT(classes.class_number) as student_classes
    FROM students 
    LEFT JOIN student_classes
    ON students.student_number=student_classes.student_number 
    LEFT JOIN classes 
    ON classes.class_number=student_classes.class_number 
    WHERE students.status=1 GROUP BY students.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hy all..I have an issue regarding a query.I have 3 tables and what I
I have this issue trying to get all the text nodes in an HTML
I currently have a issue with firefox, where all other browser behave in the
HI all, I have an issue where i have to search rows in a
First of all: I'm at Scala 2.8 I have a slight issue while using
i'm having an issue PInvoking a native function from c++... i have PInvoked all
The issue Let's say that I have example.com, example.org and example.net. All of these
My issue is as follows. We have dict that has all keys and values
I have bandage due to 5th metacarpal damage. Typing is no issue at all,
I have about 8 entities that all have a one to one relationship with

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.