cameeob2003 Posted August 1, 2006 Share Posted August 1, 2006 I am trying to use the following code and get 2 different posts from my MySQL database:[code]<?phpswitch ($_GET['page']){default:case "home":$sql = "SELECT * FROM `news` order by `id` DESC LIMIT 0,3";$result = mysql_query($sql) or die(mysql_error());$num = mysql_num_rows($result);while ($text = mysql_Fetch_array($result)) { $id = $text['id']; $title = $text['title']; $date = $text['date']; $author = $text['author']; $content = $text['content']; echo '<table border="0" cellpadding="0" cellspacing="0"><td background="images/news_1.jpg" height="19" align="left" valign="bottom" width="652">'. $title .'</td></tr><tr><td align="left" background="images/news_2.jpg">'. $content .'</td></tr><tr><td background="images/news_3.jpg" height="17"></td></tr>';echo '</table>';echo '<table border="0" cellpadding="0" cellspacing="0"><td background="images/news_4.jpg" height="19" align="left" valign="bottom" width="652">'. $title .'</td></tr><tr><td align="left" background="images/news_2.jpg">'. $content .'</td></tr><tr><td><img src="images/news_6.jpg" width="652" height="17" alt=""></td></tr>';echo '</table>';}break;}?>[/code]But when it outputs it displays 2 of each post from my news table. Is there a way to make this only display 1 of each news post while using the following html output? Quote Link to comment Share on other sites More sharing options...
Eric_Ryk Posted August 1, 2006 Share Posted August 1, 2006 It seems that you currently have 2 news items, it could be solved by changing your SQL statement:$sql = "SELECT * FROM `news` order by `id` DESC LIMIT 1"; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 1, 2006 Share Posted August 1, 2006 Well, you are getting two of each because you're displaying each record twice in two different tables.From your question, I'm not exactly sure how you want to display the records.Ken Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 1, 2006 Share Posted August 1, 2006 Not really sure what your trying to accomplish here...what you're asking and what your code does are not really the same.I did clean it up some for you:[code]switch ($_GET['page']){ default: case "home": $sql = "SELECT * FROM `news` order by `id` DESC LIMIT 3"; $result = mysql_query($sql) or die(mysql_error()); while ($text = mysql_Fetch_array($result)) { $id = $text['id']; $title = $text['title']; $date = $text['date']; $author = $text['author']; $content = $text['content']; echo ' <table border="0" cellpadding="0" cellspacing="0"> <tr> <td background="images/news_1.jpg" height="19" align="left" valign="bottom" width="652">'. $title .'</td> </tr> <tr> <td align="left" background="images/news_2.jpg">'. $content .'</td> </tr> <tr> <td background="images/news_3.jpg" height="17"></td> </tr> </table> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td background="images/news_4.jpg" height="19" align="left" valign="bottom" width="652">'. $title .'</td> </tr> <tr> <td align="left" background="images/news_2.jpg">'. $content .'</td> </tr> <tr> <td><img src="images/news_6.jpg" width="652" height="17" alt=""></td> </tr> </table>'; } break;}[/code] Quote Link to comment Share on other sites More sharing options...
cameeob2003 Posted August 1, 2006 Author Share Posted August 1, 2006 this is an example of what i am doing:[url=http://n2p.ventgaming.com/for%20ref/image%20layout/index.php]http://n2p.ventgaming.com/for%20ref/image%20layout/index.php[/url]I want the first one in the newsection to be "Blue and Silver" the next one "Orange and Silver"the one after that"Blue and Silver"Ect... I hope this helps you understand my question :) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 1, 2006 Share Posted August 1, 2006 You want alternating backgounds for your news. Is that correct?Try this:[code]<?phpswitch ($_GET['page']){ default: case "home": $sql = "SELECT * FROM `news` order by `id` DESC LIMIT 0,3"; $result = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error()); $num = mysql_num_rows($result); $table_background = 1; $td_background = 3; while ($rw = mysql_Fetch_assoc($result)) { echo '<table border="0" cellpadding="0" cellspacing="0"><td background="images/news_' . $table_background . '.jpg" height="19" align="left" valign="bottom" width="652">'. $rw['title'] .'</td></tr> <tr> <td align="left" background="images/news_2.jpg">'. $rw['content'] .'</td> </tr> <tr> <td background="images/news_' . $td_background . '.jpg" height="17"></td> </tr>'; echo '</table>'; $table_background = ($table_background == 1)?4:1; // if it's 1 set it to 4, if it's not 1 set it to 1 $td_background = ($td_background == 3)?6:3; // same idea as above } break;}?>[/code]Ken 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.