Jump to content

please help php and html tables


dude32

Recommended Posts

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

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

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.