While row displaying repeated values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pakits1582
    New Member
    • Feb 2012
    • 3

    While row displaying repeated values

    I need help..i have a while loop inside a while loop..
    and it displays repeated values.can anyone help me..thanks in advance...
    Code:
    if ($_REQUEST['sem']==2){
    			$result="select g.* from grades as g, prospectus as p where g.idno='".$_REQUEST['idno']."' and g.course='".$_REQUEST['course']."' and g.year='".$_REQUEST['year']."' and g.sem=1 and g.syear='".$_REQUEST['syear']."' and g.remarks='failed' and g.subid=p.prerequisite1";
    			$rsq=mysql_query($result);
    			if(mysql_num_rows($rsq)>=1){//if student exist in first sem..evaluate grades for second sem
    			while($grade=mysql_fetch_array($rsq)){
    				$grades=$grade['subid'];
    				//echo "".$grades."<br />";
    $race = mysql_query("SELECT DISTINCT subid FROM prospectus
    WHERE prospectus.prerequisite1
    NOT IN (
    SELECT prospectus.subid
    FROM prospectus
    WHERE prospectus.subid='".$grades."'
    ) and prospectus.sem=2
    ");
            while($sub_row = mysql_fetch_array($race)){
    			//echo "".$sub_row['subid']."<br />";
    		
    	
    	$result2="select * from subject where subid='".$sub_row['subid']."' order by subid ASC limit 0,1";
    		$rsq2=mysql_query($result2);
    		while ($r2=mysql_fetch_array($rsq2)){
    		echo "<tr>";
    		echo "<td><input type=\"hidden\" name=\"subid[]\" value=\"".$r2['subid']."\"/>".$r2['subcode']."</td><td>".$r2['subname']."</td><td>".$r2['subdesc']."</td><td>".$r2['units']."</td></tr>"; 
    			}
    		}
    	}			
    }
    the output should be:
    1
    2
    3
    4
    5
    but it displays:
    1
    2
    3
    4
    5
    1
    2
    3
    4
    5
    hope you can help me....
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    We would have to know what the data looks like.

    Comment

    • pakits1582
      New Member
      • Feb 2012
      • 3

      #3
      i have 3 tables..GRADES, PROSPECTUS and SUBJECT..

      the grade tables looks like this..
      gid| idno |course|year|se m| syear |subid|grade|re marks|
      1 |20110002|BSIT |1 | 1|2011-2012| 41 | 90 | passed|
      2 |20110002|BSIT |1 | 1|2011-2012| 5 | 90 | passed|
      3 |20110002|BSIT |1 | 1|2011-2012| 10 | 90 | passed|
      4 |20110002|BSIT |1 | 1|2011-2012| 13 | 90 | passed|
      5 |20110002|BSIT |1 | 1|2011-2012| 16 | 90 | passed|
      6 |20110002|BSIT |1 | 1|2011-2012| 18 | 70 | failed|
      7 |20110002|BSIT |1 | 1|2011-2012| 42 | 70 | failed|
      8 |20110002|BSIT |1 | 1|2011-2012| 19 | 70 | failed|
      9 |20110002|BSIT |1 | 1|2011-2012| 43 | 70 | failed|
      10 |20110002|BSIT |1 | 1|2011-2012| 25 | 90 | passed|
      11 |20110002|BSIT |1 | 1|2011-2012| 20 | 90 | passed|

      PROSPECTUS table looks like this:
      idpros|course|y ear|sem|subid|p rerequisite1|
      1 |BSIT |1 | 2| 24 | 19 |
      2 |BSIT |1 | 2| 23 | 19 |
      3 |BSIT |1 | 2| 17 | 16 |
      4 |BSIT |1 | 2| 21 | 0 |
      5 |BSIT |1 | 2| 14 | 0 |
      6 |BSIT |1 | 2| 11 | 0 |
      7 |BSIT |1 | 2| 6 | 0 |
      8 |BSIT |1 | 2| 2 | 0 |
      9 |BSIT |1 | 2| 26 | 25 |
      10 |BSIT |1 | 2| 27 | 0 |

      SUBJECT table look like this:

      subid |subcode|subnam e|units|
      41 |as12 |name1 | 3 |
      23 |gh34 |name2 | 3 |
      17 |jj22 |name3 | 3 |
      21 |ko90 |name4 | 3 |
      14 |78ju |name5 | 3 |
      11 |990o |name6 | 3 |
      6 |ty65 |name7 | 3 |
      2 |asa8 |name8 | 3 |
      26 |sd9d |name9 | 3 |
      27 |sds9 |name10 | 3 |

      hope this one can help...

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Your data doesn't match your previous post at all.

        Comment

        • pakits1582
          New Member
          • Feb 2012
          • 3

          #5
          huh?? but the data i've posted is the same..??

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            You posted that the result you're getting back is 1 2 3 4 5. But your code is actually printing out multiple values per row. That doesn't match. So I have no idea what you mean when you say it's printing back 1 2 3 4 5. When nothing in your code shows that it should print that.

            Comment

            Working...