spinsfil Posted December 14, 2010 Share Posted December 14, 2010 hi i have a db of tv shows, episodes and descriptions. they are in the db like: name | series | episode | description Friends | 1 | 1 | example Friends | 1 | 2 | example Scrubs | 1 | 1 | example I want to display it this way: Friends Series 1 Episode 1 Series 1 Episode 2 Scrubs Series 1 Episode 1 cant seem to get it to fully work - it will display it for the first show but not do more than one thanks for any help Link to comment https://forums.phpfreaks.com/topic/221645-php-whiles-and-loops/ Share on other sites More sharing options...
kenrbnsn Posted December 14, 2010 Share Posted December 14, 2010 Please post your code. Ken Link to comment https://forums.phpfreaks.com/topic/221645-php-whiles-and-loops/#findComment-1147233 Share on other sites More sharing options...
spinsfil Posted December 14, 2010 Author Share Posted December 14, 2010 $getshows = mysql_query("SELECT * FROM showsdb GROUP BY series ASC, ep ASC ORDER BY id ASC") or die (mysql_error()); echo "<table>"; while ($row = mysql_fetch_array($getshows)) { echo "<tr><td><b>$row[name]</b></td></tr>"; $row = mysql_fetch_array($getshows); $count=1; do { if ($count>2) { $i="</tr><tr>"; $count=0;} else { $i="";} echo "<tr><td>Series $row[series] Episode $row[ep]</td></tr>"; echo $i; $count++; } while ($row = mysql_fetch_array($getshows)); } echo "</table>"; So far this code is doing it correctly for just the first show... Link to comment https://forums.phpfreaks.com/topic/221645-php-whiles-and-loops/#findComment-1147241 Share on other sites More sharing options...
AbraCadaver Posted December 14, 2010 Share Posted December 14, 2010 Untested example (the query is changed, don't use group by): $getshows = mysql_query("SELECT * FROM showsdb ORDER BY name ASC") or die (mysql_error()); $name = ''; echo "<table>"; while($row = mysql_fetch_array($getshows)) { if($row['name'] != $name) { echo "<tr><td><b>".$row['name']."</b></td></tr>"; $name = $row['name']; } echo "<tr><td>Series ".$row['series']." Episode ".$row['ep']."</td></tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/221645-php-whiles-and-loops/#findComment-1147265 Share on other sites More sharing options...
spinsfil Posted December 14, 2010 Author Share Posted December 14, 2010 works - thanks Link to comment https://forums.phpfreaks.com/topic/221645-php-whiles-and-loops/#findComment-1147273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.