Expand|Select|Wrap|Line Numbers
- $sql = "SELECT DISTINCT year FROM _current_floats_config WHERE active = 'yes' ORDER BY year DESC LIMIT 2, 1";
- $result = mysql_query($sql);
- while($fetched = mysql_fetch_array($result)) {
- $ceiling = $fetched["year"];
- }
- $sql = "SELECT * FROM _current_floats WHERE active = 'yes' AND yearID <= $ceiling ORDER BY yearID DESC, name ASC";
I'm then creating another $sql query selecting all results in DESC order less than or equal to $ceiling.
What I need to do now is group these results by years, like this below:
2006
result, result, result, result, result, result, result, result, result
2005
result, result, result, result, result, result, result, result, result
2004
result, result, result
2003
result, result, result, result, result, result
etc, etc..
Here's the snippet that returns all the results without grouping them by year..
Expand|Select|Wrap|Line Numbers
- $display = 3;
- $cols = 0;
- $sql = "SELECT DISTINCT year FROM _current_floats_config WHERE active = 'yes' ORDER BY year DESC LIMIT 2, 1";
- $result = mysql_query($sql);
- while($fetched = mysql_fetch_array($result)) {
- $ceiling = $fetched["year"];
- }
- $sql = "SELECT * FROM _current_floats WHERE active = 'yes' AND yearID <= $ceiling ORDER BY yearID DESC, name ASC";
- echo $sql."<br /><br />";;
- $result = mysql_query($sql);
- if (mysql_num_rows($result) > 0 ) {
- /* while($fetched = mysql_fetch_array($result)) {
- echo $fetched["yearID"]."<br />";
- } // end WHILE statement
- } else { echo "Ooops!"; } // end IF statement
- */
- echo "<table width='100%' border='0' cellspacing='10' cellpadding='0' style='padding:10px;'>";
- //$num = 1;
- while($fetched = mysql_fetch_array($result)){
- $num = $fetched["ID"];
- if($cols == 0){
- echo "<tr>\n";
- }
- // put what you would like to display within each cell here
- if (((!empty($fetched["rendering"])) AND (!empty($fetched["rendering2"]))) OR ((!empty($fetched["rendering"])) AND (!empty($fetched["parade_pic"]))) OR ((!empty($fetched["parade_pic"])) AND (!empty($fetched["parade_pic2"])))) {
- echo "<td valign=\"top\" align=\"center\" width=\"33%\"><h1 style=\"font-size:96%;\"><a title=\"$fetched[name]\" href=\"current.php?year=$fetched[yearID]&id=$fetched[ID]\">$fetched[name]</a></h1><br /><script type=\"text/javascript\">new fadeshow(fadeimages".$num.", 150, 150, 0, 5000, 0)</script></td>\n";
- $cols++;
- } elseif (!empty($fetched["rendering"])) {
- echo "<td valign=\"top\" align=\"center\" width=\"33%\"><h1 style=\"font-size:96%;\"><a title=\"$fetched[name]\" href=\"current.php?year=$fetched[yearID]&id=$fetched[ID]&viewing=rendering\">$fetched[name]</a></h1><img class=\"reflect ropacity25 rheight15\" alt=\"$fetched[name]\" src=\"dynamic/images/show_image.php?filename=$fetched[rendering]&width=150&height=150\"></td>\n";
- $cols++;
- } elseif (!empty($fetched["parade_pic"])) {
- echo "<td valign=\"top\" align=\"center\" width=\"33%\"><h1 style=\"font-size:96%;\"><a title=\"$fetched[name]\" href=\"current.php?year=$fetched[yearID]&id=$fetched[ID]&viewing=parade_pic\">$fetched[name]</a></h1><img class=\"reflect ropacity25 rheight15\" alt=\"$fetched[name]\" src=\"dynamic/images/show_image.php?filename=$fetched[parade_pic]&width=150&height=150\"></td>\n";
- $cols++;
- } else {
- echo "<td valign=\"top\" align=\"center\" width=\"33%\"><h1 style=\"font-size:96%;\"><a title=\"$fetched[name]\" href=\"current.php?year=$fetched[yearID]&id=$fetched[ID]\">$fetched[name]</a></h1><img class=\"reflect ropacity25 rheight15\" alt=\"$fetched[name]\" src=\"dynamic/images/show_image.php?filename=none.jpg&width=150&height=150\"></td>\n";
- $cols++;
- }
- if($cols == $display){
- echo "</tr>\n\n";
- $cols = 0;
- }
- } // end IF statement
- // added the following so it would display the correct html
- if($cols != $display && $cols != 0){
- $neededtds = $display - $cols;
- for($i=0;$i<$neededtds;$i++){
- echo "<td> </td>\n";
- }
- echo "</tr>\n</table>\n";
- } else {
- echo "</table>\n";
- } // end WHILE statement
- //
- // THERE ARE NO RESULTS FOR THE GIVEN YEAR
- //
- } else { echo "<p style=\"font-size:2.4em;color:#FF0C12;margin-bottom:-25px;\">Oops!</p><p>We couldn't find any floats in our database beyond the past two years.</p><p>You can check back later or select a year under the <strong>Our Floats</strong> heading on the left to continue.</p>"; }
- }