WHERE 句をリンクに接続する必要があります。これが私のコードです:
<body>
<?php
function toiletPaper($input) {
// Clean input
return $input;
}
$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);
// process form when posted
$query = "SELECT * FROM searchacts";
$options['PriceLow'] = array("desc" => "Price (Low to High)","query" => " ORDER BY price ASC");
$options['PriceHigh'] = array("desc" => "Price (High to Low)","query" => " ORDER BY price DESC");
$options['NameAZ'] = array("desc" => "Name (A-Z)","query" => " ORDER BY name ASC");
$options['NameZA'] = array("desc" => "Name (Z-A)","query" => " ORDER BY name DESC");
$query = "SELECT * FROM searchacts";
$filter['partybands'] = array("desc" => "Party Bands","query" => " WHERE category='Party Bands'");
// Important: function name is made up
$cleanValue = toiletPaper($_REQUEST['value']);
if (array_key_exists($cleanValue, $options)) {
$query .= $query.$options[$cleanValue];
}
$result = mysql_query($query);
$num = mysql_num_rows($result);
echo "<a href='".$_SERVER['PHP_SELF']."'>All</a>";
foreach ($options as $key => $value) {
echo "<a href='".$_SERVER['PHP_SELF']."?value=".$key."'>".$value['desc']."</a>";
}
?>
<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>
<?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>
だから私は私の句を持っています:
elseif($_POST['value'] == 'partybands') {
$query = "SELECT * FROM searchacts
WHERE category='Party Bands'";
}
たとえば、リンクに接続する必要があります。<a href="">Party Bands</a>
データをフィルタリングするためにかなり多くのwhere句があるので、どうすればそれを行うことができますか。
ありがとう