cturner Posted October 21, 2006 Share Posted October 21, 2006 I am trying to display article titles underneath the month and year they were added to the database table but the month and year isn't displaying. Can someone please help me solve this problem? Thanks in advance.Here is the code that I am working with:[code]require "config2.php";if(!isset($_GET['page'])) { $page = 1;} else { $page = $_GET['page'];}// Define the number of results per page$max_results = 5;// Figure out the limit for the query based// on the current page number$from = (($page * $max_results) - $max_results);$result = mysql_query ("SELECT DATE_FORMAT(selectMonth, '%M') AS month, DATE_FORMAT(selectYear, '%Y') AS year, articletitle, articleid FROM items LIMIT $from, $max_results");if ( mysql_num_rows ( $result ) > 0 ){ $c_month = ''; $c_year = ''; echo "<br />"; while ( $row = mysql_fetch_assoc ( $result ) ) { if ( $row['year'] != $c_year ) { echo "<h3>" . $row['year'] . "</h3><br />"; $c_year = $row['year']; } if ( $row['month'] != $c_month ) { echo "\t<h4>" . $row['month'] . "</h4><br />"; $c_month = $row['month']; } echo "\t\t" . $row['articletitle'] . "<br />"; }}// Figure out the total number of results in DB:$total_results = mysql_result(mysql_query("SELECT COUNT(*) AS Num FROM `items`"),0);// Figure out the total number of pages. Always round up using ceil()$total_pages = ceil($total_results / $max_results);// Build Page Number Hyperlinksecho "<center>";if ($page == 1) { echo "Previous ";} else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\">Previous</a> ";}for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; }}if ($page == $total_pages) { echo " Next";} else { echo " <a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\">Next</a>";}echo "</center>";mysql_close();[/code] 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.