stublackett Posted October 1, 2009 Share Posted October 1, 2009 Hi, I'm working on http://www.berwickrangers.net/news.php As you can see the news list is rather huuuuuuuuuge. What I'm looking to do is archive the news, Possibly week by week. How could I do this? Any tutorials that you may be aware of out there. Probably looking to do it as a drop down too. Any help appreciated. Cheers Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 1, 2009 Share Posted October 1, 2009 Hi stublackett, You could have a drop-down box and match by month, for example: <select name="newsmonth"> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> </select> Then, get the selected month by using: $newsmonth = $_POST['newsmonth']; And then you could just perform a MySQL query matching the $newsmonth to the required month in the database, obviously you would need to change the option values to match the method you used to store the month in the database. Something like this should work. Hope this helps. Quote Link to comment Share on other sites More sharing options...
stublackett Posted November 5, 2009 Author Share Posted November 5, 2009 Just started to look at this.. Been damn busy. I've got a select menu set up in HTML Like so : <form action="news.php" method="POST"> <select name="newsmonth"> <option value="" selected="selected"> </option> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <input type="submit" name="go" value="Go" /> </form> I just need to sort the SQL selection out. Its finding the month to match which is proving difficult. The date string is currently echo'ed out as DD/MM/YY So my PHP Code (As I think it should look is as follows : <?php $newsmonth = $_POST['newsmonth']; $result = mysql_query("SELECT *, DATE_FORMAT( date, '%m' )AS uk_date FROM $db_table WHERE uk_date = $newsmonth ORDER BY nid DESC"); ?> But its not showing anything... I suspect its something to do with the %m can anyone help? Cheers Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted November 5, 2009 Share Posted November 5, 2009 SELECT * FROM $db_table WHERE MONTH(date) = $newsmonth ORDER BY nid DESC; You'll get a problem once your site has been online for a year though. When you select January you would get news items from January 2009 and January 2010 (and January 2011 later on). What I would do is to list them in reverse chronological order, but introduce pagination so you can do like "Earlier entires". We have a pagination tutorial on PHP Freaks. Quote Link to comment Share on other sites More sharing options...
stublackett Posted November 5, 2009 Author Share Posted November 5, 2009 I'll have a look at the pagination stuff, Cheers. Was thinking it could be very tricky once the year comes round. Ideally I'd like the news from season to season, Which may be difficult. Still having difficulty tho...... That seems to work in PHP My Admin, Just not in the actual page. What I need is an IF Statement that shows ALL news items, Unless the Archive Form has been submitted.. My script is as follows <?php if (isset($_POST['posted'])) { $newsmonth = $_POST['newsmonth']; $result = mysql_query("SELECT * FROM $db_table WHERE MONTH(date) = $newsmonth ORDER BY nid DESC"); while($myrow = mysql_fetch_assoc($result)) {//begin of loop $nid = $myrow['nid']; $headline = $myrow['headline']; $date = $myrow['uk_date']; // Show Pulled Through News Items echo "<ul> <li> <h2><span class='newsdate'>($date)</span> <a href='newsitem.php?nid=$nid' title='$headline'>$headline</a> </h2> </li> </ul>"; } } else { include("includes/news-select.php"); }//End While loop ?> Quote Link to comment Share on other sites More sharing options...
Bricktop Posted November 5, 2009 Share Posted November 5, 2009 Hi Stuart, Your script is relying on $_POST['posted'] to be set before performing the query. Is that set? Post your HTML to confirm. Also, your else statement is just including "news-select.php" and doing nothing else. Change your code to read: <?php if ($_SERVER['REQUEST_METHOD']=='POST') { $newsmonth = $_POST['newsmonth']; $result = mysql_query("SELECT * FROM $db_table WHERE MONTH(date) = $newsmonth ORDER BY nid DESC"); } else { $result = mysql_query("SELECT * FROM $db_table ORDER BY nid DESC"); include("includes/news-select.php"); } while($myrow = mysql_fetch_assoc($result)) {//begin of loop $nid = $myrow['nid']; $headline = $myrow['headline']; $date = $myrow['uk_date']; // Show Pulled Through News Items echo "<ul> <li> <h2><span class='newsdate'>($date)</span> <a href='newsitem.php?nid=$nid' title='$headline'>$headline</a> </h2> </li> </ul>"; } ?> Hope this helps. Quote Link to comment Share on other sites More sharing options...
stublackett Posted November 5, 2009 Author Share Posted November 5, 2009 Works a treat, Thanks Bricktop. I suspect that posted var wasn't going. It was the only thing that was blocking the data from being outputted to the browser. Now works nice and smoothly. Onto pagination... Should be fun 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.