Advertisement
Guest User

News list

a guest
Sep 23rd, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1.                 <?php
  2.                 for ($i = 0; $i < 7; $i++)
  3.                 {
  4.                 $sectionName = '';
  5.                 $sectionCutoffMax = 0;
  6.                 $sectionCutoffMin = 0;
  7.        
  8.                 switch ($i)
  9.                 {
  10.                 case 0:
  11.            
  12.                 $sectionName = 'I dag';
  13.                 $sectionCutoffMax = time();
  14.                 $sectionCutoffMin = time() - 86400;
  15.                 break;
  16.                
  17.             case 1:
  18.            
  19.                 $sectionName = 'I g&aring;r';
  20.                 $sectionCutoffMax = time() - 86400;
  21.                 $sectionCutoffMin = time() - 172800;
  22.                 break;
  23.                
  24.             case 2:
  25.            
  26.                 $sectionName = 'Denne uge';
  27.                 $sectionCutoffMax = time() - 172800;
  28.                 $sectionCutoffMin = time() - 604800;
  29.                 break;
  30.                
  31.             case 3:
  32.            
  33.                 $sectionName = 'Sidste uge';
  34.                 $sectionCutoffMax = time() - 604800;
  35.                 $sectionCutoffMin = time() - 1209600;
  36.                 break;
  37.                
  38.             case 4:
  39.            
  40.                 $sectionName = 'Denne m&aring;ned';
  41.                 $sectionCutoffMax = time() - 1209600;
  42.                 $sectionCutoffMin = time() - 2592000;
  43.                 break;
  44.                
  45.             case 5:
  46.            
  47.                 $sectionName = 'Sidste m&aring;ned';
  48.                 $sectionCutoffMax = time() - 2592000;
  49.                 $sectionCutoffMin = time() - (60 * 60 * 24 * 365);
  50.                 break;
  51.             }
  52.        
  53.             $q = "SELECT * FROM cms_news WHERE published >= " . $sectionCutoffMin . " AND published <= " . $sectionCutoffMax .  " ORDER BY published DESC LIMIT 50";
  54.             $getArticles = mysql_query($q);
  55.  
  56.             if (mysql_num_rows($getArticles) > 0)
  57.             {
  58.                 echo '<h2>' . $sectionName . '</h2>
  59.                <ul>';
  60.  
  61.             while ($a = mysql_fetch_assoc($getArticles))
  62.             {
  63.         ?>
  64.        
  65.         <li><?php if($news_id !== $a['id']){ echo"<a href=\"".$path."/news/".$a['id']."\">"; } ?>
  66.  
  67.         <?php echo $a['title']; ?> &raquo;</a>
  68.         <?php if($news_id !== $a['id']){ echo"</a>"; } ?></li>
  69.         <?php }
  70.         echo '</ul>';
  71.         }
  72.         }
  73.         ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement