Jump to content

Sorting/filtering some data


kartul

Recommended Posts

hello.

 

I'm working on one page right now. the idea of it is that people with certain right can add movies there and others can view and browse them. so far, I've been managed to do most of the things by myself. but now, what i need to make is 'multi-sorting'. it's kind of hard to explain exactly... i set up a example page for it to my personal webspace. there are 3 'categories' - genre, first letter and type. right now people can sort/filter movies with only one option (by genre, first letter or type). but what i need is to sort/filter these with at least two options like genre and type. I've tried to search google, phpclasses but nothing. here's some code I'm using.

 

<?php
$sort = $_GET['sort'];
$sorts = array('action','adventure','animation','biography','comedy','crime','documentary','drama','family','fantasy','foreign','history','horror','musical','mystery','romance','scifi','sport','thriller','war','western');
$sort_by = array('action' => 'Action', 'adventure' => 'Adventure', 'animation' => 'Animation', 'biography' => 'Biopic', 'comedy' => 'Comedy', 'crime' => 'Crime', 'documentary' => 'Documentary', 'drama' => 'Drama', 'family' => 'Family', 'fantasy' => 'Fantasy', 'foreign' => 'Foreign Language', 'history' => 'History', 'horror' => 'Horror', 'musical' => 'Musical', 'mystery' => 'Mystery', 'romance' => 'Romance', 'scifi' => 'Sci-Fi', 'sport' => 'Sport', 'thriller' => 'Thriller', 'war' => 'War', 'western' => 'Western');

$sorts_a = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','num');
$sort_by_a = array('a' => 'A', 'b' => 'B', 'c' => 'C', 'd' => 'D', 'e' => 'E', 'f' => 'F', 'g' => 'G', 'h' => 'H', 'i' => 'I', 'j' => 'J', 'k' => 'K', 'l' => 'L', 'm' => 'M', 'n' => 'N', 'o' => 'O', 'p' => 'P', 'q' => 'Q', 'r' => 'R', 's' => 'S', 't' => 'T', 'u' => 'U', 'v' =>' V', 'w' => 'W', 'x' => 'X', 'y' => 'Y', 'z' => 'Z', 'num' => '#');

$sorts_g = array('mhd', '720p', 'thd');
$sort_by_g = array('mhd' => 'm-HD', '720p' => '720p', 'thd' => 't-HD');

//do display. same code for all three 'categories'
$x=1;
$c = count($sort_by);
foreach($sort_by AS $url => $link) {
$line = ($x == $c) ? "" : " - ";
echo "<a href=\"./index.php?sort=".$url."\">".$link."</a>" . $line . "\n";
$x++;
}
//if $sort doesn't exist then show all movies
if(!$sort || !isset($sort, $sorts, $sorts_a, $sorts_g)) {
//display all code. not necessary i think
}else {
if($sort == "action") {
	$gen = "action";
	$what = "=1";
	$wut = "action";
	//this is function to display all action movies. in this function there are: pagination for this sorting/filtering, displaying code (same like displaying all.).
	displayGenreSort($gen,$what,$wut);
}
if($sort == "adventure") {
	$gen = "adventure";
	$what = "=1";
	$wut = "adventure";
	displayGenreSort($gen,$what,$wut);
}
if($sort == "animation") {
	$gen = "animation";
	$what = "=1";
	$wut = "animation";
	displayGenreSort($gen,$what,$wut);
}
//and so on with all of them (genres, firstletters, type)...

?>

 

now, hopefully you understand what i want to make. and what i need is help on how do create this. if you have or you know some pre-made functions or classes, have any idea how do make this, please be kind and tell. any help is welcome.

Link to comment
https://forums.phpfreaks.com/topic/159907-sortingfiltering-some-data/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.