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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:05:14+00:00 2026-06-13T14:05:14+00:00

I have here a SQL query to get course information from the data base.

  • 0

I have here a SQL query to get course information from the data base. The variable courses is an array saved by Session from the previous page. Here is what courses[] looks like if I var_dump it. I have selected 3 courses to be put into the session.

array(3) 
{ 
[0]=> string(7) "CAD8405" 
[1]=> string(7) "CON8413" 
[2]=> string(7) "ENG8328" 
}

My $selectedYear variable varies between 2012 to 2014. The is also saved by session. Below is where I have the problem. My query is fine, there is no need to check that. I cannot get $courseCode to show up as my Course.CourseCode='$courseCode', therefore my query doesn’t work.

This is what I found to be where it gets kinda confusing. The $courses array returns a normal array. but when I do $courses[0] = $courseCode; then var_dump($courseCode) = null This is what leads me to believe that data I need as my course ID’s are the keys to the $courses[] array. When trying to access the $courses[1], the code thinks its a multidimensional array with the key as the first data. But I could be wrong
Is there better way to extract the key of my array?

for($i = 0; $i < count($courses); $i++)
{
    //$courses[$i] = $courseCode;
    $courseCode = $courses[$i];
    $comfirmationString = "SELECT Course.CourseCode, Course.Title, Course.WeeklyHours, Semester.SemesterCode FROM Course, Semester, CourseOffer
    WHERE Semester.YearNum='$selectedYear' AND Course.CourseCode='$courseCode'
    AND Course.CourseCode=CourseOffer.CourseCode AND Semester.SemesterCode=CourseOffer.SemesterCode";

if($comfirmationResult = mysqli_query($link, $comfirmationString))
    {
        while($row = mysqli_fetch_assoc($comfirmationResult))
        {
            echo "<tr><td>$row[CourseCode]</td><td>$row[Title]</td><td>$row[WeeklyHours]</td><td>$row[SemesterCode]</td></tr>";
        }
    }
    else
    {
        echo "<p>Query error: " + mysqli_error($link) + "</p>";
    }
}

Below is the code to show how I have saved the $courses[] variable: I get the results of a query, and if the check box is checked, this courseID gets thrown into the courses[] array.

if($Result2013 = mysqli_query($link, $string2013))
    {
        echo "<form action='CourseSelection.php' method='get'>
        <table><tr><th>Code</th><th>Course Title</th><th>Hours</th><th>Term</th><th>Select</th></tr>";
        while($row2013 = mysqli_fetch_assoc($Result2013))
        {
            echo "<tr><td>$row2013[CourseCode]</td><td>$row2013[Title]</td><td>$row2013[WeeklyHours]</td>
            <td>$row2013[Term]</td><td><input type='checkbox' name='courses[]' value=$row2013[CourseCode]></td></tr>";
        }
        echo "</table>";
    }
  • 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-13T14:05:15+00:00Added an answer on June 13, 2026 at 2:05 pm

    You might want to modify your query to associate the compound values to an easier to read value, like so:

    $comfirmationString = "SELECT Course.CourseCode as courseCode, Course.Title as courseTitle, Course.WeeklyHours as courseWeeklyHours, Semester.SemesterCode as semesterCode FROM Course, Semester, CourseOffer
    WHERE Semester.YearNum='$selectedYear' AND Course.CourseCode='$courseCode'
    AND Course.CourseCode=CourseOffer.CourseCode AND Semester.SemesterCode=CourseOffer.SemesterCode";
    

    You also need to wrap your variables in brackets, like so:

    echo "<tr><td>{$row['CourseCode']}</td><td>{$row['courseTitle']}</td><td>{$row['courseWeeklyHours']}</td><td>$row[SemesterCode]</td></tr>";
    

    and so on.

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

Sidebar

Related Questions

I have an SQL query I get from a configuration file, this query usually
I have a NHibernate criteria, from which I need to get the SQL query.
I have a procedure in T-SQL from here which works perfectly when I execute
I have just downloaded SQL Server 2005 express edition from here: To be used
here's my problem: I have an SQL query that makes 4 calls to a
I have this long sql query here.. SELECT c.clientid, c.clientname, c.billingdate, case when (select
I have the following Linq-to-SQL query. On line #5 I'm trying to get the
I have this SQL code here.. SELECT cl.clientid, cl.clientname, cl.billingdate, cp.startdate, cp.expiration, (SELECT COUNT(*)
enter code here I have a table on SQL server 2005 with bigint primary
I am writing a stored procedure in SQL Server 2008. Here I have a

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.