By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,395 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

While row displaying repeated values

P: 3
I need help..i have a while loop inside a while loop..
and it displays repeated values.can anyone help me..thanks in advance...
Expand|Select|Wrap|Line Numbers
  1. if ($_REQUEST['sem']==2){
  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";
  3.             $rsq=mysql_query($result);
  4.             if(mysql_num_rows($rsq)>=1){//if student exist in first sem..evaluate grades for second sem
  5.             while($grade=mysql_fetch_array($rsq)){
  6.                 $grades=$grade['subid'];
  7.                 //echo "".$grades."<br />";
  8. $race = mysql_query("SELECT DISTINCT subid FROM prospectus
  9. WHERE prospectus.prerequisite1
  10. NOT IN (
  11. SELECT prospectus.subid
  12. FROM prospectus
  13. WHERE prospectus.subid='".$grades."'
  14. ) and prospectus.sem=2
  15. ");
  16.         while($sub_row = mysql_fetch_array($race)){
  17.             //echo "".$sub_row['subid']."<br />";
  18.  
  19.  
  20.     $result2="select * from subject where subid='".$sub_row['subid']."' order by subid ASC limit 0,1";
  21.         $rsq2=mysql_query($result2);
  22.         while ($r2=mysql_fetch_array($rsq2)){
  23.         echo "<tr>";
  24.         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>"; 
  25.             }
  26.         }
  27.     }            
  28. }
  29.  
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....
Feb 12 '12 #1
Share this Question
Share on Google+
5 Replies


Rabbit
Expert Mod 10K+
P: 12,347
We would have to know what the data looks like.
Feb 12 '12 #2

P: 3
i have 3 tables..GRADES, PROSPECTUS and SUBJECT..

the grade tables looks like this..
gid| idno |course|year|sem| syear |subid|grade|remarks|
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|year|sem|subid|prerequisite1|
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|subname|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...
Feb 13 '12 #3

Rabbit
Expert Mod 10K+
P: 12,347
Your data doesn't match your previous post at all.
Feb 13 '12 #4

P: 3
huh?? but the data i've posted is the same..??
Feb 13 '12 #5

Rabbit
Expert Mod 10K+
P: 12,347
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.
Feb 13 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.