Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - echo missing entries
    primarykey
    data
    text
    <p>I have a problem.</p> <p>I have three tables <strong>class_tbl,subject_tbl, and *student_tbl</strong>. class_tbl has 3 columns *"class_id, subject_id, and student_id".* while subject_tbl has 4 columns *"subject_id,subject_name,subject_yr,subject_sem"* and lastly *student_tbl has 2 columns "student_id and student_name".*</p> <p>class_tbl has these rows:</p> <pre><code>**[class_id || subject_id || student_id]** || 1001 || 2002 || 3003 || 1002 || 2003 || 3003 || 1003 || 2004 || 3003 </code></pre> <p>subject_tbl has 5 rows:</p> <pre><code>**[subject_id || subject_name || subject_yr || subject_sem]** || 2002 || Math || 2010 || 1st || 2003 || Science || 2010 || 1st || 2004 || History || 2010 || 1st || 2005 || PE || 2010 || 1st || 2006 || Social Studies || 2010 || 1st </code></pre> <p>student_tbl has 1 row: depending on the number of students actually</p> <pre><code>**[student_id || student_name]** || 3003 || John Parker </code></pre> <p>The goal here is that the query will echo the last 2 subjects which is PE and Social Studies so that I can insert them to class_tbl. The echo is telling me that I dont have 2 entries for the 2 subject during that semester and school year. The query will not echo the subjects which are already in the entries of class_tbl which are Math,Science, and History. How do I query and echo the missing subjects of that semester and year? I really cant come up with any idea. Help tnx!</p> <p>The code here displays all subjects of that school_yr and semester.</p> <pre><code> if (isset ($db1)&amp;&amp;$db1!=""){ } &lt;?php $student_id = $_POST['student_id']; $sem = $_POST['sem']; $yr = $_POST['yr']; $list = mysql_query("SELECT * FROM class_tbl LEFT JOIN subject_tbl ON class_tbl.subject_id = subject_tbl.subject ID WHERE student_id = '$student_id' OR subject_sem = '$sem' OR subject_yr = '$yr' ORDER BY subject_id asc"); while($row_list=mysql_fetch_assoc($list)) { echo $row_list['subject_id']; if($row_list['subject_id']==$db1){echo "selected"; } echo $row_list['subject_name']; } </code></pre> <p>The example output would be:</p> <p>You have 2 missing subjects "PE and Social Studies." </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload