seany123 Posted June 13, 2011 Share Posted June 13, 2011 okay im trying to collect data from my database which is about TV shows, im trying to collect data by each season. Example, $get_season1 = mysql_query("SELECT * FROM `$show` WHERE `season` = '1' ORDER BY `episode` ASC"); $get_season2 = mysql_query("SELECT * FROM `$show` WHERE `season` = '2' ORDER BY `episode` ASC"); $get_season3 = mysql_query("SELECT * FROM `$show` WHERE `season` = '3' ORDER BY `episode` ASC"); $get_season4 = mysql_query("SELECT * FROM `$show` WHERE `season` = '4' ORDER BY `episode` ASC"); $get_season5 = mysql_query("SELECT * FROM `$show` WHERE `season` = '5' ORDER BY `episode` ASC"); $get_season6 = mysql_query("SELECT * FROM `$show` WHERE `season` = '6' ORDER BY `episode` ASC"); $get_season7 = mysql_query("SELECT * FROM `$show` WHERE `season` = '7' ORDER BY `episode` ASC"); $get_season8 = mysql_query("SELECT * FROM `$show` WHERE `season` = '8' ORDER BY `episode` ASC"); $get_season9 = mysql_query("SELECT * FROM `$show` WHERE `season` = '9' ORDER BY `episode` ASC"); but each tv series has its own amount of seasons so is there anyway i can make a while loop to do the above until null? 2. once i have the data, im trying to put them into html tables... like so: <table width="700"> <tbody> <tr onclick="toggleItem('myTbody1')" bgcolor="#CCC" onMouseover="this.bgColor='grey'"onMouseout="this.bgColor='#CCC'"><td align="center"><a href="#">Season 1 (24 Episodes)</a></td></tr> </tbody> <tbody id="myTbody1"> <?php while ($row = mysql_fetch_array($get_season1)) { ?> <tr> <td><a href="watch.php?r=<?= $row['episode_id']?>"><?= $row['episode_name'] ?></a></td> </tr> <?php } ?> </tbody> </table> <table width="700"> <tbody> <tr onclick="toggleItem('myTbody2')" bgcolor="#CCC" onMouseover="this.bgColor='grey'"onMouseout="this.bgColor='#CCC'"><td align="center"><a href="#">Season 2 (24 Episodes)</a></td></tr> </tbody> <tbody id="myTbody2"> <?php while ($row = mysql_fetch_array($get_season2)) { ?> <tr> <td><a href="watch.php?r=<?= $row['episode_id']?>"><?= $row['episode_name'] ?></a></td> </tr> <?php } ?> </tbody> </table> but again i dont know how many seasons there are so is there a loop i could run to show tables when the top queries didnt equal null or something? lastly. the tables above are using some javascript to collapse and expand, eg. var tblBody1 = document.getElementById('myTbody1'); if (!document.cookie.match(/hide_table/) || document.cookie.match(/hide_table=1/)) { tblBody1.style.display = 'none'; } var tblBody2 = document.getElementById('myTbody2'); if (!document.cookie.match(/hide_table/) || document.cookie.match(/hide_table=1/)) { tblBody2.style.display = 'none'; } which again im having to problem of not know the amount of seasons that will be needed. any help would be great! seany123 Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 13, 2011 Share Posted June 13, 2011 Never do queries in loop or how you are doing it there. All you need is ONE QUERY: SELECT * FROM `$show` ORDER BY `season` ASC, `episode` ASC You will than have all the records first ordered by season, then ordered by episode. Then process the records using PHP 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.