Dynamikz 0 Newbie Poster

Hi everyone,

I'm a bit of a noob on the forum so please correct me if this is posted in the wrong area/or post is incorrect.

I'm currently working on a new website (http://www.worldwidemixtapes.com) and currently stuck on the "sort by" section at the top of the page.

What I'm trying to do is sort the mixtape results (stored in mysql db) by the option selection the the combobox/selection boxes.

The first box sorts by: Newest/Oldest, Most/Least Views, and Best/Worst Ratings

The second box sorts by range: All Time, 30 Days, 3 Months, 6 Months, Past Year

Here is my HTML code for the two selection boxes:

<select class="sortby" onchange="window.location.href='index.php?tapes='+this.options[this.selectedIndex].value">
<option value="newest" selected="selected">Newest</option>
<option value="mostviews">Most Views</option>
<option value="bestrating">Best Rating</option>
<option value="">----------</option>
<option value="worstrating">Worst Rating</option>
<option value="leastviews">Least Views</option>
<option value="oldest">Oldest</option>
</select>&nbsp;&nbsp;
<select class="sortby" onchange="window.location.href='index.php?tapes=&amp;range='+this.options[this.selectedIndex].value">
<option value="all">All Time</option>
<option value="1mo">Last 30 Days</option>
<option value="3mo">Last 3 Months</option>
<option value="6mo">Last 6 Months</option>
<option value="year">Past Year</option>
</select>

As you can see, I already started adding the "onchange" to switch the window but I'm lost at how I would use php to pull the data from mysql to display the mixtapes on the page based off the option selected.

I also have some php at the beginning of the home.php that pulls the mixtapes from mysql and also provides the pagination.

Here is that code:

<?php
	//	check to make sure that "page" is set and a number
	//	if its not set or not a number, then default the page to 1
	if (isset($_GET["p"]) && is_numeric($_GET["p"])) {
		$page = $_GET["p"];
	} else {
		$page = 1;
	}

	//	get the total number of mixtapes
	$query = mysql_query("SELECT * FROM mixtapes") or die(mysql_error());
	$total_mixtapes = mysql_num_rows($query);
	
	$per_page = 16;	//	results to display per page
	$offset = (($per_page * $page) - $per_page);	//	offset from 0
	$total_pages = ceil($total_mixtapes / $per_page);	//	total number of pages
	
	//	get our results from the database for the page that we want
	$query = mysql_query("SELECT * FROM mixtapes ORDER BY id DESC LIMIT ".$offset.", ".$per_page) or die(mysql_error());
	
	//	generate our pagination
	$pagination = pagination("16.php?p=", $page, $total_pages);
	

?>

And here is the loop that I programmed to display 4 mixtapes per row:

<div class="mixtape-row">
	  <?php 
	  		for ($n=1; $n<=3; $n++) {
				$mixtape = mysql_fetch_array($query);  
	  			echo '<div class="mixtape-container">';
				echo $mixtape["mixtape-dj"].$mixtape["mixtape-cover"].$mixtape["mixtape-title"].$mixtape["mixtape-preview"];
				echo '</div>';
      			}
			
			if ($n=4)
				$mixtape = mysql_fetch_array($query); 
				echo '<div class="mixtape-container-end">';
				echo $mixtape["mixtape-dj"].$mixtape["mixtape-cover"].$mixtape["mixtape-title"].$mixtape["mixtape-preview"];
				echo '</div>';
	  ?>   
	</div>

Can someone point me in the right direction or at least help get me started with getting the "Sort by" section working on the home.php page?

Thanks!

(I'll be glad to get someone a coffee or energy drink for helping me figure this out)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.