dude32 Posted February 20, 2007 Share Posted February 20, 2007 I want to be able to search through my movie collection. I currently have 2 formats I have DVD and HDDVD. What I want to do is use arrays to break them into categories and sub categories. The main category is movies. The sub categories are DVD and HDDVD under those will be drama, documentary, comedy, and action. I want to use a HTML form to: 1. look at the full list 2. look at each format 3. look at each categories and 4. look at each category and format together. Right now I am just interested in using static arrays and I will figure out how to make them dynamic later. I already have the arrays they have been tested and work I just want a way to sort them with an HTML table using an HTML form. Link to comment https://forums.phpfreaks.com/topic/39256-please-help-php-and-html-tables/ Share on other sites More sharing options...
tom100 Posted February 20, 2007 Share Posted February 20, 2007 Not sure if this is what you meant or not. <?php function setSortVar(&$item, $key, $sortBy) { $item[0]=$item[$sortBy]; } function myArraySort($x, $y) { if ($x[0] == $y[0]) { return 0; } else if ($x[0] < $y[0]) { return -1; } return 1; } $myCollection = array(); $myCollection[0][0]=""; // Sorting Value $myCollection[0][1]="Die Die Die"; // Name $myCollection[0][2]="Movie"; // Main Category $myCollection[0][3]="DVD"; // Sub Category $myCollection[0][4]="Drama"; // Type of movie $myCollection[1][0]=""; // Sorting Value $myCollection[1][1]="Worm Race"; // Name $myCollection[1][2]="Movie"; // Main Category $myCollection[1][3]="DVD"; // Sub Category $myCollection[1][4]="Action"; // Type of movie $myCollection[2][0]=""; // Sorting Value $myCollection[2][1]="Ha ha."; // Name $myCollection[2][2]="Movie"; // Main Category $myCollection[2][3]="HDDVD"; // Sub Category $myCollection[2][4]="Comedy"; // Type of movie $sortBy=1; //Look for sort vars if (isset($_GET['sortBy'])) { switch ($_GET['sortBy']) { case 1: $sortBy=1; break; case 2: $sortBy=2; break; case 3: $sortBy=3; break; case 4: $sortBy=4; break; default: $sortBy=1; break; } } array_walk($myCollection, 'setSortVar', $sortBy); usort($myCollection, 'myArraySort'); print_r($myCollection); ?> Link to comment https://forums.phpfreaks.com/topic/39256-please-help-php-and-html-tables/#findComment-189180 Share on other sites More sharing options...
JBS103 Posted February 20, 2007 Share Posted February 20, 2007 Just as a side note: If you are looking for something you might be able to maintain, it might be neat to use XML and then have that formatted and sorted by some code. It's up to you. Multidimensional arrays can get a little messy sometimes. Link to comment https://forums.phpfreaks.com/topic/39256-please-help-php-and-html-tables/#findComment-189216 Share on other sites More sharing options...
dude32 Posted February 20, 2007 Author Share Posted February 20, 2007 I already have the arrays. I need a way to use HTML drop down boxes or radio buttons to sort this data and print it to tables based on what I select. Link to comment https://forums.phpfreaks.com/topic/39256-please-help-php-and-html-tables/#findComment-189868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.