0

I want the while loop to output based on matching column value of "id".

    $query = "SELECT s.id,s.last,s.first,s.course1,s.course2,s.course3
            ,e.id,e.last,e.first,e.course1,e.course2,e.course3
            FROM $startsem1 s
            JOIN $endsem1 e on s.id = e.id";
    $result = mysql_query($query) or die(mysql_error());

    while ($row = mysql_fetch_assoc($result))
    {
         print_r($row); echo "<br><br>";
    }

2 Answers 2

2

Use a join:

SELECT s.id,s.last,s.first,s.course1,s.course2,s.course3
      ,e.id,e.last,e.first,e.course1,e.course2,e.course3
  FROM $startsem1 s
  JOIN $endsem1 e on s.id = e.id
Sign up to request clarification or add additional context in comments.

2 Comments

I edited my code above, but the while loop only outputs the courses from $endsem1, but not $startsem1.
try using alias for the column value like select s.id as sid, e.id as eid, that way might help you.
0

You use binary operator &, not logical && in the while loop condition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.