tqla Posted May 9, 2007 Share Posted May 9, 2007 Hi. I have this database that is sorted in the order that I put the data in. I want it in reverse order by the $row_WADAalbums['Year'] column. I've tried to use the sort function but I really don't know how and failed miserably. By the way, this code was generated by WA DataAssist, that's why there's a lot of it (damn code generators). Thanks in advance for your help. <?php require_once('db.php'); ?> <?php $currentPage = $_SERVER["PHP_SELF"]; ?> <?php if (!session_id()) session_start(); if (isset($_SESSION["albums_Results_QueryString"]) && ($_SESSION["albums_Results_QueryString"] != "") && !isset($_SERVER["QUERY_STRING"]) ){ header("Location: albums_Results.php?".str_replace("&totalRows_","&old_totalRows_",$_SESSION["albums_Results_QueryString"])); } else{$_SESSION["albums_Results_QueryString"] = isset($_SERVER["QUERY_STRING"])?$_SERVER["QUERY_STRING"]:""; } ?> <?php $maxRows_WADAalbums = 1000; $pageNum_WADAalbums = 0; if (isset($_GET['pageNum_WADAalbums'])) { $pageNum_WADAalbums = $_GET['pageNum_WADAalbums']; } $startRow_WADAalbums = $pageNum_WADAalbums * $maxRows_WADAalbums; mysql_select_db($database_disc, $disc); $query_WADAalbums = "SELECT * FROM albums"; $query_limit_WADAalbums = sprintf("%s LIMIT %d, %d", $query_WADAalbums, $startRow_WADAalbums, $maxRows_WADAalbums); $WADAalbums = mysql_query($query_limit_WADAalbums, $disc) or die(mysql_error()); $row_WADAalbums = mysql_fetch_assoc($WADAalbums); if (isset($_GET['totalRows_WADAalbums'])) { $totalRows_WADAalbums = $_GET['totalRows_WADAalbums']; } else { $all_WADAalbums = mysql_query($query_WADAalbums); $totalRows_WADAalbums = mysql_num_rows($all_WADAalbums); } $totalPages_WADAalbums = ceil($totalRows_WADAalbums/$maxRows_WADAalbums)-1; ?> <?php $queryString_WADAalbums = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_WADAalbums") == false && stristr($param, "totalRows_WADAalbums") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_WADAalbums = "&" . htmlentities(implode("&", $newParams)); } } $queryString_WADAalbums = sprintf("&totalRows_WADAalbums=%d%s", $totalRows_WADAalbums, $queryString_WADAalbums); ?> <?php //WA AltClass Iterator class WA_AltClassIterator { var $DisplayIndex; var $DisplayArray; function WA_AltClassIterator($theDisplayArray = array(1)) { $this->ClassCounter = 0; $this->ClassArray = $theDisplayArray; } function getClass($incrementClass) { if (sizeof($this->ClassArray) == 0) return ""; if ($incrementClass) { if ($this->ClassCounter >= sizeof($this->ClassArray)) $this->ClassCounter = 0; $this->ClassCounter++; } if ($this->ClassCounter > 0) return $this->ClassArray[$this->ClassCounter-1]; else return $this->ClassArray[0]; } } ?><?php //WA Alternating Class $WARRT_AltClass1 = new WA_AltClassIterator(explode("|", "WADAResultsRowDark|")); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Results albums</title> <link href="WA_DataAssist/styles/Modular_Slate.css" rel="stylesheet" type="text/css" /> <link href="WA_DataAssist/styles/Arial.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="WADAResultsContainer"> <div class="WADAResultsHeader"> <div class="WADAHeaderText"> Discography</div> <?php if ($totalRows_WADAalbums > 0) { // Show if recordset not empty ?> <div class="WADAResults"> <div class="WADAResultsNavigation"> <div class="WADAResultsCount">Records <?php echo ($startRow_WADAalbums + 1) ?> to <?php echo min($startRow_WADAalbums + $maxRows_WADAalbums, $totalRows_WADAalbums) ?> of <?php echo $totalRows_WADAalbums ?></div> <div class="WADAResultsNavTop"> </div> <table class="WADAResultsTable" border="0" cellpadding="0" cellspacing="0"> <tr> <th class="WADAResultsTableHeader">Cover:</th> <th width="40" class="WADAResultsTableHeader">Title:</th> <th width="30" class="WADAResultsTableHeader">Year Released:</th> <th width="30" class="WADAResultsTableHeader">Chart Position:</th> <th width="30" class="WADAResultsTableHeader">Type:</th> <th width="30" class="WADAResultsTableHeader">Formats:</th> <th width="30" class="WADAResultsTableHeader">Buy Now:</th> </tr> <?php do { ?> <tr class="<?php echo $WARRT_AltClass1->getClass(true); ?>"> <td class="WADAResultsTableCell"><a href="albums_Detail.php?ID=<?php echo(rawurlencode($row_WADAalbums['ID'])); ?>" ><?php echo($row_WADAalbums['sCover']); ?></a></td> <td class="WADAResultsTableCell"><a href="albums_Detail.php?ID=<?php echo(rawurlencode($row_WADAalbums['ID'])); ?>" ><?php echo($row_WADAalbums['Title']); ?></a></td> <td class="WADAResultsTableCell"><?php echo($row_WADAalbums['Year']); ?></td> <td class="WADAResultsTableCell"><?php echo($row_WADAalbums['Chart']); ?></td> <td class="WADAResultsTableCell"><?php echo($row_WADAalbums['Type']); ?></td> <td class="WADAResultsTableCell"><?php echo($row_WADAalbums['Formats']); ?></td> <td class="WADAResultsTableCell"><?php echo($row_WADAalbums['Buy']); ?></td> </tr> <?php } while ($row_WADAalbums = mysql_fetch_assoc($WADAalbums)); ?> </table> <div class="WADAResultsNavigation"> <div class="WADAResultsCount">Records <?php echo ($startRow_WADAalbums + 1) ?> to <?php echo min($startRow_WADAalbums + $maxRows_WADAalbums, $totalRows_WADAalbums) ?> of <?php echo $totalRows_WADAalbums ?></div> </div> </div> <?php } // Show if recordset not empty ?> <?php if ($totalRows_WADAalbums == 0) { // Show if recordset empty ?> <?php } // Show if recordset empty ?> </div> </body> </html> <?php mysql_free_result($WADAalbums); ?> Quote Link to comment https://forums.phpfreaks.com/topic/50615-solved-help-me-sort-this-pleasemy-head-hurts-from-trying/ Share on other sites More sharing options...
Lumio Posted May 9, 2007 Share Posted May 9, 2007 Select `column1` FROM `table` WHERE `column2` = 3 ORDER BY `column3` LIMIT 0,30; Quote Link to comment https://forums.phpfreaks.com/topic/50615-solved-help-me-sort-this-pleasemy-head-hurts-from-trying/#findComment-248802 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.