Guest User

Untitled

a guest
Jan 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. $query_articles = mysql_query("SELECT * FROM articles ORDER BY article_date DESC LIMIT 30") or die(mysql_error());
  2. $row_articles = mysql_fetch_assoc($query_articles);
  3.  
  4. // Show article #1
  5.  
  6. // Then loop through articles 2-7
  7.  
  8. // Then show article #8
  9.  
  10. // Then loop through articles 9-30
  11.  
  12. $query_articles = mysql_query("SELECT * FROM articles ORDER BY article_date DESC LIMIT 32") or die(mysql_error());
  13. $row_articles = mysql_fetch_assoc($query_articles);
  14.  
  15. $shown_articles = array(1, 8);
  16. $article_index = 1;
  17. foreach ($row_articles as $article) {
  18. do {
  19. if (in_array($article_index, $shown_articles)) {
  20.  
  21. echo '<p>'.$article_index.' ';
  22. echo $row_articles['title'];
  23. echo '</p>';
  24.  
  25. } else {
  26.  
  27. echo '<p>'.$article_index.' ';
  28. echo $row_articles['title'];
  29. echo '</p>';
  30.  
  31. }
  32. $article_index++;
  33. } while($row_articles = mysql_fetch_assoc($query_articles));
  34. }
  35.  
  36. $query_articles = mysql_query("SELECT * FROM articles ORDER BY article_date DESC LIMIT 32") or die(mysql_error());
  37.  
  38. $shown_articles = array(1, 8);
  39. $article_range = range(9, 30);
  40. $article_index = 1;
  41.  
  42. while($row_articles = mysql_fetch_assoc($query_articles)) {
  43. if (in_array($article_index, $shown_articles)) {
  44.  
  45. echo '<p>'.$article_index.' ';
  46. echo $row_articles['title'];
  47. echo '</p>';
  48.  
  49. } elseif (in_array($article_index, $article_range)) {
  50.  
  51. echo '<p>'.$article_index.' ';
  52. echo $row_articles['title'];
  53. echo ' - 9-30</p>';
  54.  
  55. } else {
  56.  
  57. echo '<p>'.$article_index.' ';
  58. echo $row_articles['title'];
  59. echo ' - 2-7</p>';
  60.  
  61. }
  62. $article_index++;
  63. }
  64.  
  65. $rows = new ArrayIterator($row_articles);
  66.  
  67. $articles = new NoRewindIterator($rows);
  68.  
  69. foreach ($articles as $i => $article)
  70. {
  71. switch ($i)
  72. {
  73. case 1:
  74. article_display($article);
  75. article_list(new LimitIterator($articles, 0, 6));
  76. break;
  77.  
  78. case 8:
  79. article_display($article);
  80. article_list(new LimitIterator($articles, 0, 21));
  81. break;
  82.  
  83. default:
  84. throw new Excpetion(sprintf("Unexpected i: %d", $i));
  85. }
  86. }
  87.  
  88. $query_articles = mysql_query("SELECT * FROM articles ORDER BY article_date DESC LIMIT 30") or die(mysql_error());
  89. $row_articles = mysql_fetch_assoc($query_articles);
  90.  
  91. $i=0;
  92. foreach($row_articles as $article) {
  93. if($i % 8 == 0) {
  94. // do stuff for row 0, 8 ..
  95. }
  96. else {
  97. // do stuff for other rows
  98. }
  99. $i++;
  100. }
  101.  
  102. $shown_articles = array(1, 8);
  103. $article_index = 1;
  104. foreach ($row_article as $article) {
  105. if (in_array($article_index, $shown_articles)) {
  106. // Show article
  107. } else {
  108. // Do something else
  109. }
  110. $article_index++;
  111. }
  112.  
  113. $query_articles = mysql_query("SELECT * FROM articles ORDER BY article_date DESC LIMIT 32") or die(mysql_error());
  114.  
  115. $shown_articles = array(1, 8);
  116. $article_index = 1;
  117. while ($row_articles = mysql_fetch_assoc($query_articles)) {
  118. if (in_array($article_index, $shown_articles)) {
  119.  
  120. echo '<p>'.$article_index.' ';
  121. echo $row_articles['title'];
  122. echo '<br>Stuff for articles in $shown_articles';
  123. echo '</p>';
  124.  
  125. } else {
  126.  
  127. echo '<p>'.$article_index.' ';
  128. echo $row_articles['title'];
  129. echo '<br>Stuff for articles NOT in $shown_articles';
  130. echo '</p>';
  131.  
  132. }
  133. $article_index++;
  134. }
Add Comment
Please, Sign In to add comment