Guber-X Posted February 20, 2008 Share Posted February 20, 2008 for how i have my webpage set up, I have the news array displayed in 2 different ways on the front page. I need it to display the latest news in one box, then display the rest in the other box. It sounds easy, but i guess im just a noob with this haha. can anyone help me out? Ive been trying to figure this out for a few days now :-\ here is how my code is written: <table cellpadding="0" cellspacing="0" border="0" width="420"> <tr> <td colspan="3"><img src="images/news.jpg" /></td> </tr> <tr> <td background="images/left-news.jpg" width="14"><img src="images/left-news.jpg" /></td> <td background="images/color.jpg" width="398" height="100%"> <? $result = mysql_query("SELECT * FROM news ORDER by id DESC LIMIT 1"); if (!$result) { die("query failed: " . msql_error()); } while ($row = mysql_fetch_array($result)) { list($id, $date, $name, $news) = $row; $news = nl2br($news); print(' <b>'.$date.':</b><br><br>'. $news.'<br>' ); } ?> </td> <td background="images/right.jpg" width="8"><img src="images/right.jpg" /></td> </tr> <tr> <td colspan="3"><img src="images/news-bottom.jpg" /></td> </tr> </table> <? $result = mysql_query("SELECT * FROM news ORDER by id DESC LIMIT 5"); if (!$result) { die("query failed: " . msql_error()); } while ($row = mysql_fetch_array($result)) { list($id, $date, $name, $news) = $row; $news = nl2br($news); print(' <table cellpadding="0" cellspacing="0" border="0" width="420"> <tr> <td width="16"><img src="images/box/Top-left.jpg" /></td> <td background="images/box/Top-center.jpg" width="398"><img src="images/box/Top-center.jpg" /></td> <td width="8"><img src="images/box/Top-right.jpg" /></td> </tr> <tr> <td background="images/box/left.jpg" width="16"><img src="images/box/left.jpg" /></td> <td background="images/box/color.jpg" width="398"> <b>'.$date.':</b><br><br>'. $news.'<br> </td> <td background="images/box/right.jpg" width="8"><img src="images/box/right.jpg" /></td> </tr> <tr> <td width="16"><img src="images/box/Bottom-left.jpg" /></td> <td background="images/box/Bottom-center.jpg" width="398"><img src="images/box/Bottom-center.jpg" /></td> <td width="8"><img src="images/box/Bottom-right.jpg" /></td> </tr> </table> '); } ?> Quote Link to comment Share on other sites More sharing options...
Chris92 Posted February 20, 2008 Share Posted February 20, 2008 What you could do is set the id's of your two latest rows into an array, then use a simple if to make sure they aren't in the array so they wont be shown in your other box. <table cellpadding="0" cellspacing="0" border="0" width="420"> <tr> <td colspan="3"><img src="images/news.jpg" /></td> </tr> <tr> <td background="images/left-news.jpg" width="14"><img src="images/left-news.jpg" /></td> <td background="images/color.jpg" width="398" height="100%"> <? $result = mysql_query("SELECT * FROM news ORDER by id DESC LIMIT 1"); if (!$result) { die("query failed: " . msql_error()); } while ($row = mysql_fetch_array($result)) { list($id, $date, $name, $news) = $row; $news = nl2br($news); $newsArray[] = $id; print(' <b>'.$date.':</b><br /><br />'. $news.'<br>' ); } ?> </td> <td background="images/right.jpg" width="8"><img src="images/right.jpg" /></td> </tr> <tr> <td colspan="3"><img src="images/news-bottom.jpg" /></td> </tr> </table> <? $result = mysql_query("SELECT * FROM news ORDER by id DESC LIMIT 7"); if (!$result) { die("query failed: " . msql_error()); } while ($row = mysql_fetch_array($result)) { list($id, $date, $name, $news) = $row; if( !in_array("$id", $newsArray) ) { $news = nl2br($news); print(' <table cellpadding="0" cellspacing="0" border="0" width="420"> <tr> <td width="16"><img src="images/box/Top-left.jpg" /></td> <td background="images/box/Top-center.jpg" width="398"><img src="images/box/Top-center.jpg" /></td> <td width="8"><img src="images/box/Top-right.jpg" /></td> </tr> <tr> <td background="images/box/left.jpg" width="16"><img src="images/box/left.jpg" /></td> <td background="images/box/color.jpg" width="398"> <b>'.$date.':</b><br><br>'. $news.'<br> </td> <td background="images/box/right.jpg" width="8"><img src="images/box/right.jpg" /></td> </tr> <tr> <td width="16"><img src="images/box/Bottom-left.jpg" /></td> <td background="images/box/Bottom-center.jpg" width="398"><img src="images/box/Bottom-center.jpg" /></td> <td width="8"><img src="images/box/Bottom-right.jpg" /></td> </tr> </table> '); } } ?> Quote Link to comment Share on other sites More sharing options...
Guber-X Posted February 20, 2008 Author Share Posted February 20, 2008 haha, thnx... that worked. I think i need to do some reading on php more. Ive been dealing with php for several years, but i only used some basic database stuff. so i dont quite understand everything yet thnx a lot 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.