Ok I think I understand 
So this is what i have now:
Code:
<body>
<?php
$username="USERNAME";
$password="PASSWORD";
$database="DATABASE";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM searchacts";
$result=mysql_query($query);
$type = $_POST['type']; // you could give these better names in your html form
$order = $_POST['value']; // ditto
$permitted_types = array(
'tributebands' => 'Tribute Bands',
'rockandpop' => 'Rock and Pop',
);
$permitted_order = array(
'PriceHigh' => 'price',
'PriceLow' => 'price ASC',
'NameAZ' => 'name',
'NameZA' => 'name ASC',
);
$sql = "SELECT * FROM searchacts "; // start of your select
$where = "";
$order_by = "";
if( array_key_exists($type, $permitted_types) ){ // filter incoming vs a white list of permitted values
$where = "WHERE category = ' . $permitted_types[$type]. ' ";
}
if( array_key_exists($order, $permitted_order) ){ // filter incoming vs a white list of permitted values
$where = "ORDER BY " . $permitted_order[$order];
}
echo $sql . $where . $orderby ;
$result = mysql_query($query);
$num=mysql_numrows($result);
?>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' >
<select name="value">
<option value="all">All</option>
<option value="PriceLow">Price (Low to High)</option>
<option value="PriceHigh">Price (High to Low)</option>
<option value="NameAZ">Name (A-Z)</option>
<option value="NameZA">Name (Z-A)</option>
</select>
<br />
<input type='submit' value = 'Re-Order'>
</form>
<input type=hidden name=type value ='tributebands' >
<a href="http://www.EXAMPLE.co.uk/searchtesting.php?value=rockandpop">Rock and Pop</a>
<a href="http://www.EXAMPLE.co.uk/searchtesting.php?value=tributebands">Tribute Bands</a>
<?php
$i=0;
while ($i < $num) {
$image=mysql_result($result,$i,"image");
$name=mysql_result($result,$i,"name");
$category=mysql_result($result,$i,"category");
$description=mysql_result($result,$i,"description");
$stamps=mysql_result($result,$i,"stamps");
$stickmen=mysql_result($result,$i,"stickmen");
$price=mysql_result($result,$i,"price");
$view=mysql_result($result,$i,"view");
$actpagelink=mysql_result($result,$i,"actpagelink");
?>
<a href="<?php echo $actpagelink; ?>" class="searchitem">
<div class="searchimage"><img src="<?php echo $image; ?>"/></div>
<div class="searchtext">
<div class="searchname"><?php echo $name; ?></div>
<div class="searchcategory"><?php echo $category; ?></div>
<div class="searchdescription"><?php echo $description; ?></div>
</div>
<div class="searchstamps"><img src="<?php echo $stamps; ?>" /></div>
<div class="searchstickmen"><img src="<?php echo $stickmen; ?>" /></div>
<div class="searchprice"><span class="pricefrom">from</span>£<?php echo $price; ?></div>
<div class="searchview"><img src="<?php echo $view; ?>" /></div>
</a>
<?php
$i++;
}
mysql_close();
?>
</body>
So this is what I understand:
The array_key_exists checks the inputted data against the permitted values. But I'm unsure of how to execute them through my form and URL variable?
Bookmarks