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 8188003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:45:26+00:00 2026-06-07T02:45:26+00:00

I am trying to view values from two separate tables using a foreach loop.

  • 0

I am trying to view values from two separate tables using a foreach loop. The user chooses a “Start semester” and an “End semester” from a drop down list, and those two semesters are stored into an array called $semesterarray

<table style='width: 75%; text-align: left;' cellpadding = '4'>
<tr bgcolor=#000090>
<th><FONT COLOR = #FFFFFF><b><?php echo $startsem ?></b></th>
<th><FONT COLOR = #FFFFFF><b><?php echo $endsem ?></b></th>
</tr>

// If $semesterarray contains 10 and 11, I want to be able to view the
// courses taken in the 10 semester and the 11 semester under two separate columns.

<?php
function getSemesterDetails($semester) 
{
    $output = "";
    $semA = $semester."reg";
    $query = "SELECT course1,course2,course3 FROM $semA";
    $result = mysql_query($query) or die(mysql_error());

    while ($row = mysql_fetch_array($result))
    {

            // row displays: [course1]=> [course2]=> [course3]=>

            // Add semester code to array Keys to indicate proper semester
            // [course1.11]=> [course2.11]=> [course3.11]=>

            foreach ($row as $key => $value)
            {
                $row[$key.".".$semester] = $value;
                unset($row[$key]);
            }

        $startcourse1 = $row['course1.'.$semester];
        $startcourse2 = $row['course2.'.$semester];
        $startcourse3 = $row['course3.'.$semester];
        $startcoursesarray = array($startcourse1, $startcourse2, $startcourse3);
        $startcourses = implode("<br>", $startcoursesarray);

        $endcourse1 = $row['course1.'.$semester];
        $endcourse2 = $row['course2.'.$semester];
        $endcourse3 = $row['course3.'.$semester];
        $endcoursesarray = array($endcourse1, $endcourse2, $endcourse3);
        $endcourses = implode("<br>", $endcoursesarray);

        echo "<tr bgcolor=#ABB5F6>
        <td>$startcourses</td>
        <td>$endcourses</td>
        </tr>";
    }
}

foreach ($midsemarrayA as $key => $semester)
{
echo getSemesterDetails($semA);
}

?>

Any ideas?

  • 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-07T02:45:27+00:00Added an answer on June 7, 2026 at 2:45 am

    This should be enough for you to make a start:

    function getSemesterDetails ($semester) {
        $output = "";
    
        $query = "SELECT course1,course2,course3 FROM $semester";
        $result = mysql_query($query) or die(mysql_error());
    
        while ($row = mysql_fetch_array($result)) {
                // row displays: [course1]=> [course2]=> [course3]=>
    
                // Add semester code to array Keys to indicate proper semester
                // [course1.11]=> [course2.11]=> [course3.11]=>
    
                foreach ($row as $key => $value) {
                    $row[$key.".".$semester] = $value;
                    unset($row[$key]);
                }
    
            $startcourse1 = $row['course1.'.$semester];
            $startcourse2 = $row['course2.'.$semester];
            $startcourse3 = $row['course3.'.$semester];
            $startcoursesarray = array($startcourse1, $startcourse2, $startcourse3);
            $startcourses = implode("<br>", $startcoursesarray);
    
            $endcourse1 = $row['course1.'.$semester];
            $endcourse2 = $row['course2.'.$semester];
            $endcourse3 = $row['course3.'.$semester];
            $endcoursesarray = array($endcourse1, $endcourse2, $endcourse3);
            $endcourses = implode("<br>", $endcoursesarray);
    
            $output .= "<tr bgcolor=#ABB5F6>
            <td>$startcourses</td>
            <td>$endcourses</td>
            </tr>";
        }
    
    return $output;
    }
    
    foreach ($semesterarray as $key => $semester) {
         getSemesterDetails($semester);
    }
    

    You’ll want to get it to return an array of values rather than a string, but shifting it into a subroutine should do the trick.

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

Sidebar

Related Questions

I'm trying to pass a bundle of two values from a started class to
I am trying to get values from a view which i have the code
I'm trying to code a way to pass the values from two spinners into
I'm trying to pass a value from my database to the view in asp.net
i am trying to get checkbox value ,using c# In grid view the datasource
I'm trying to view the contents of a topic using activemq-admin . This is
I'm trying to view a users tweets from my app but twitter responses with
I'm trying to change view controllers based on a user's selection in a UIAlertView
Trying to create a black line in my view to separate text blocks but
I am trying to retrieve a set of values from database and assigned it

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.