extrovertive Posted August 15, 2006 Share Posted August 15, 2006 This is my output:[b]ENGINEERING[/b] Electrical Engr[b]EXAMS [/b]ACT[b]EXAMS[/b] PSAT[b]EXAMS[/b] SAT[b]EXAMS[/b] SAT II Chemistry[b]EXAMS[/b] SAT II Physics[b]HUMANITIES [/b]Philosophy[b]HUMANITIES[/b] Religious Studies[b]MATH [/b]Algebra 10-12[b]MATH [/b]Algebra 7-9...Based on getting a result from several tables.[code=php:0]$result = mysql_query($query) or die(mysql_error()); while(list($category, $subject) = mysql_fetch_row($result)) { echo "<strong>". strtoupper($category) ."</strong>\n"; echo ucwords($subject) . "<br/>\n"; }[/code]Now, the category is redundant. I just want to output[b]ENGINEERING [/b]Electrical Engr[b]EXAMS [/b]ACTPSATSATSAT II ChemistrySAT II Physics... and so onHow is this possible to do in my while loop? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 15, 2006 Share Posted August 15, 2006 Check for change of category[code]<?php$prevCat = '';while(list($category, $subject) = mysql_fetch_row($result)){ if ($prevCat != $category) { echo "<strong>". strtoupper($category) ."</strong>\n"; $prevCat = $category; } echo ucwords($subject) . "<br/>\n"; }?>[/code] Quote Link to comment Share on other sites More sharing options...
extrovertive Posted August 15, 2006 Author Share Posted August 15, 2006 Wow, easy logic. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.