Jump to content

[SOLVED] Help me sort this please...My head hurts from trying.


Recommended Posts

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);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.