Drezard Posted February 14, 2007 Share Posted February 14, 2007 Hello, Im trying to make a news script, except im currently stuck. I need someone to finish this off for me (or atleast guide me) Now, I connect to the MySQL Database on another script that uses this class, so dont worry about that. Okay heres the script: <?php class news_report { function news_new() { echo "<form action='' method='post'> Subject: <input type='text' size='200' name='subject'><br> News: <input type='text'size='10000' name='news'><br> <input type='submit' name='submit'> </form>"; if (isset($_POST['news'])) { $subject = $_POST['subject']; $news = $_POST['news']; $date = date("Ymdgi"); $time = date("g:i A D d F"); $query ="INSERT INTO news_all (date, subject, news, time) VALUES ('$date', '$subject', '$news', '$time')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo "News Added"; } } function news_all() { $query = "SELECT date, subject, news, time FROM news_all ORDER BY date"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_row($result)) { } } } } ?> Now, I want it too output the first 5 bits of news. In order of the date. So the most recent ones first. I also want it to display the subject at the top, then the time, then the news so.... Subject Time News Subject Time News Like that. Now, how would i do that? Quote Link to comment Share on other sites More sharing options...
simcoweb Posted February 14, 2007 Share Posted February 14, 2007 $query = "SELECT date, subject, news, time FROM news_all ORDER BY date LIMIT 5"; Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 14, 2007 Share Posted February 14, 2007 something like this then: $query = "SELECT date, subject, news, time FROM news_all ORDER BY date LIMIT 5"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) { echo <<<html <table border="0" width="100%" cellpadding="0" cellspacing="0"> html; while($row = mysql_fetch_row($result)) { $row['date'] = date("jS F, Y \a\\t h:ia", strtotime($row['date'])); //change the date to a better format. echo <<<html <tr> <td>{$row['subject']}</td> </tr> <tr> <td>Posted on {$row['date']}</td> </tr> <tr> <td>{$news}</td> </tr> <tr><td height="5"></td> </tr> html; } echo <<<html </table> html; } hope thats sort of what your looking for. 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.