0
$check = mysql_query('SELECT * FROM course_completion_criteria GROUP BY module');

foreach($check as $c)
{
   $module = $c->module; //echo $module;
   if($module == 'quiz')
   {
      $query1 = mysql_query('SELECT * FROM table1');     
      echo '<table>
            <th>Name</th>
            <th>Time</th>
      foreach($query1 as $q)
      {
         $name = $q->name;
         $time = $q->time;
         echo '<tr><td>'.$name.'</td>
                   <td>'.$time.'</td>
               </tr>';
      }
      echo '</table>';
   } 

   if($module == 'scorm')
   {
      $query2 = mysql_query('SELECT * FROM table2');
      echo '<table>
             <th>Name</th>
             <th>Time</th>
      foreach($query1 as $q)
      {
         $name = $q->name;
         $time = $q->time;
         echo '<tr><td>'.$name.'</td>
                   <td>'.$time.'</td>
               </tr>';
      }
      echo '</table>';
   } 
}

The above code should work case 1 : If $module is test1 case 2 : If $module is test2 case 3 : If $module is both test1 and test2

My code isn't working in CASE 3 and it displays two tables, but i want 2rows in the same table Could anyone help me?

1
  • 1
    How can $module be both "test1" and "test2" at the same time? Commented Dec 18, 2011 at 6:55

2 Answers 2

1

You have at least one error

if($module = 'test1')

should be

if($module == 'test1')

Also read about switch/case statement in PHP

UPD: Case 3 code

$module = []
foreach($check as $c)
{
   $module[] = $c->module; //echo $module;
}
if (count($module) == 1) {
  if($module == 'quiz')
  {
     //CASE_1
  } 

   if($module == 'scorm')
   {
     //CASE_2
   } 
}else{
   //CASE_3
}
Sign up to request clarification or add additional context in comments.

5 Comments

But this isn't the error, may be posted here was the mistake, I will correct now
hm Then I don't really understand what means CASE 3? $module is a string. How does string can be BOTH test1 and test2?
This is in MOODLE. Admin will set quiz and scorm in frontend to complete a course and student completes both to complete a course. Now Iam getting the activity either quiz or scorm from criteria table and checking them Here Admin can set either only quiz/ only scorm / one quiz and one scorm. I was able to get output for first two, but in third case Iam getting two tables but need one table with 2 different rows(quiz,scorm)
Lol I'm still not sure that understand your idea, but look at code in UPD.
Ya the code was ok, but I don't have a separate query for CASE 3. Like If $module is quiz, then first query should execute and If $module is scorm, then second query should execute in different rows but not in two tables
0

You dont have condition for case3:

else {  //for CASE3
$query3 = mysql_query('SELECT * FROM table_you_want_data_from');
...
}

1 Comment

Hi Sudhir, Can we do any modifications in the above code to get CASE 3 here

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.