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? Link to comment https://forums.phpfreaks.com/topic/17588-simple-mysql-array-help/ 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] Link to comment https://forums.phpfreaks.com/topic/17588-simple-mysql-array-help/#findComment-74944 Share on other sites More sharing options...
extrovertive Posted August 15, 2006 Author Share Posted August 15, 2006 Wow, easy logic. Thanks! Link to comment https://forums.phpfreaks.com/topic/17588-simple-mysql-array-help/#findComment-74947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.