Medicine Posted February 24, 2012 Share Posted February 24, 2012 Hi All, I have a 'Newspaper' in a game I'm coding. My plan was to have an edition every week and on average 15 articles a week. I would set this out like so. . <? $select_paper=mysql_query("SELECT * FROM paper WHERE id=1"); while($the=mysql_fetch_object($select_paper)){ ?> <table width=100% class=table> <tr> <td> <td width=50% style=border: none; background-color: transparent; valign=top> <table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center> <tr> <td width=500 class='tableheading'><?php echo "$the->title"; ?><center> </center></td> </tr> <tr > <td class="profilerow" align=left><center><?php echo "$the->news"; ?> </td> </tr> <tr > <td class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?> </td> </tr> </table> <br> </td> <? } ?> With that repeated for 15 articles per edition. BUT! To save time, space and complication, I would rather do it using something like this. . $select = mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC"); $num = mysql_num_rows($select); Could someone tell me how to intergrate this with the layout tables as show in code #1? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/257692-order-article-by-id/ Share on other sites More sharing options...
spiderwell Posted February 24, 2012 Share Posted February 24, 2012 have you tried putting the sql you want in place of the current sql, that should do it really, perhaps with LIMIT 15 tacked on the end of the sql so only 15 records return. $select_paper=mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC LIMIT 15"); Quote Link to comment https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320739 Share on other sites More sharing options...
Medicine Posted February 24, 2012 Author Share Posted February 24, 2012 Yeah that's what I need, I just don't know how to make it show in the tables as shown in code #1 if you get me? I put that line of code and that's great but it won't show in the layout i want? Quote Link to comment https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320741 Share on other sites More sharing options...
spiderwell Posted February 24, 2012 Share Posted February 24, 2012 well i think because it has a half finished table in the html part try this: <? $select_paper=mysql_query("SELECT * FROM paper WHERE id=1"); while($the=mysql_fetch_object($select_paper)){ ?> <table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center> <tr> <td width=500 class='tableheading'><?php echo "$the->title"; ?><center> </center></td> </tr> <tr > <td class="profilerow" align=left><center><?php echo "$the->news"; ?> </td> </tr> <tr > <td class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?> </td> </tr> </table> <br> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320743 Share on other sites More sharing options...
Medicine Posted February 24, 2012 Author Share Posted February 24, 2012 No the first code I posted works absolutely fine, but i have to re-enter it for each article that's written, as you see $select_paper=mysql_query("SELECT * FROM paper WHERE id=1"); I have to do it for id=2 and so on. When i change that line of code to the order by it doesn't show anything. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320751 Share on other sites More sharing options...
spiderwell Posted February 24, 2012 Share Posted February 24, 2012 try changing the sql $select_paper=mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC LIMIT 15"); Quote Link to comment https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320755 Share on other sites More sharing options...
Medicine Posted February 24, 2012 Author Share Posted February 24, 2012 Yeah already have done if you see the second code in my first post. My code looks like this now <table class="Main" width="65%" cellpadding="0" cellspacing="0"> <tr><td class="Tableheading">Newspaper</td></tr> <tr><td class="subtableheader"><img src="images/newspaper.jpg" alt="paper"/></td></tr> </table> <? $select = mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC"); $the = mysql_num_rows($select); ?> <table width=100% class=table> <tr> <td> <td width=50% style=border: none; background-color: transparent; valign=top> <table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center> <tr> <td width=500 class='tableheading'><?php echo "$the->title"; ?><center> </center></td> </tr> <tr > <td class="profilerow" align=left><center><?php echo "$the->news"; ?> </td> </tr> <tr > <td class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?> </td> </tr> </table> <br> </td> </html> Quote Link to comment https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320758 Share on other sites More sharing options...
spiderwell Posted February 24, 2012 Share Posted February 24, 2012 you still need the while statement to loop through the record set: <table class="Main" width="65%" cellpadding="0" cellspacing="0"> <tr><td class="Tableheading">Newspaper</td></tr> <tr><td class="subtableheader"><img src="images/newspaper.jpg" alt="paper"/></td></tr> </table> <table width=100% class=table> <? $select = mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC"); while($the=mysql_fetch_object($select_paper)){ ?> <tr> <td> <td width=50% style=border: none; background-color: transparent; valign=top> <table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center> <tr> <td width=500 class='tableheading'><?php echo "$the->title"; ?><center> </center></td> </tr> <tr > <td class="profilerow" align=left><center><?php echo "$the->news"; ?> </td> </tr> <tr > <td class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?> </td> </tr> </table> </td> </tr> <? } ?> </table> </html> Quote Link to comment https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320762 Share on other sites More sharing options...
Medicine Posted February 24, 2012 Author Share Posted February 24, 2012 Ahhh yeah that's done it! Thanks for your help! Now just have to re-do the layout! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320764 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.