wat ik nu heb is dat bij het klikken op de submit button de zoekresultaten worden meegegeven in de link.
wat ik wil dat ik bij het keuze maken van bijv. dropdown het gelijk in de link wordt meegeven voordat ik op de submit button klik.
Hoe kan ik dat oplossen?
dit is mijn script:
index.php
<?php
require_once('inc/functions.php');
$sql = "SELECT DISTINCT bk.title AS Title, YEAR(bk.date_released) AS Year, bk.price AS Price, cat.name AS Category, aut.name AS Author
FROM books bk
JOIN categories cat
ON cat.id = bk.category
JOIN books_covers bk_co
ON bk_co.book_id = bk.id
JOIN covers co
ON co.id = bk_co.cover_id
JOIN books_authors bk_aut
ON bk_aut.book_id = bk.id
JOIN authors aut
ON aut.id = bk_aut.author_id
JOIN books_languages bk_lan
ON bk_lan.book_id = bk.id
JOIN languages lan
ON lan.id = bk_lan.lang_id
JOIN books_locations bk_loc
ON bk_loc.book_id = bk.id
JOIN locations loc
ON loc.id = bk_loc.location_id
";
if (isset($_GET['srch_for'])){
$locations = array();
$getters = array();
$queries = array();
foreach($_GET as $key => $value) {
$temp = is_array($value) ? $value : trim($value);
if(!empty($temp)){
list($key) = explode("-",$key);
if($key == 'srch_locations'){
array_push($locations, $value);
}
if (!in_array($key, $getters)){
$getters[$key] = $value;
}
}
}
if (!empty($locations)){
$loc_qry = implode(",",$locations);
}
if (!empty($getters)){
foreach($getters as $key => $value){
${$key} = $value;
switch($key){
case 'srch_for':
array_push($queries,"(bk.title LIKE '%$srch_for%' || bk.description LIKE '%$srch_for%' || bk.isbn LIKE '%$srch_for%')");
break;
case 'srch_category':
array_push($queries,"bk.categories = $srch_category");
break;
case 'srch_cover':
array_push($queries, "bk_co.cover_id = $srch_cover");
break;
case 'srch_author':
array_push($queries, "bk_aut.author_id = $srch_author");
break;
case 'srch_language':
array_push($queries, "bk_lan.lang_id = $srch_language");
break;
case 'srch_year':
array_push($queries, "YEAR(bk.date_released) = $srch_year");
break;
case 'srch_locations':
array_push($queries, "bk_loc.location_id IN ($loc_qry)");
break;
}
}
}
if (!empty($queries)) {
$sql .= " WHERE ";
$i=1;
foreach($queries as $query){
if ($i < count($queries)){
$sql .= $query." AND ";
} else {
$sql .= $query;
}
$i++;
}
}
$sql .= " ORDER BY bk.title ASC";
}
mysql_select_db($database,$conndb);
$rs = mysql_query($sql,$conndb) or die(mysql_error());
$rows = mysql_fetch_assoc($rs);
$tot_rows = mysql_num_rows($rs);
?>
<html xmlns="http://www.w2,org//1999/xhtml">
<head>
<meta http-equiv="Content-Type" Content="text/html; charset=UTF-8" />
<title>Advanced search form</title>
<link href="style/core.css" rel="stylesheet" type="text/css" />
</head>
<div id="out">
<div id="ph">
<div id="phin">
<h1>Advanced Search Form</h1>
<h3>Web design tutorials by Sebastian Sulinski</h3>
</div>
</div>
<div id="wr">
<div id="hd"></div>
<div id="cnt">
<h2>Search for the book</h2>
<form id="search_form" name="search_form" method="get" action="">
<table border="0" cellspacing="0" cellpadding="0" class="tbl_search">
<tr>
<th scope="row"><label for="srch_for">Search for:</label></th>
<td><input type="text" name="srch_for" id="srch_for" class="f_fld" value="<?php getSticky(1,'srch_for'); ?>"></td>
<th><label for="srch_category">Category:</table></th>
<td><?php getCategories(); ?></td>
</tr>
<tr>
<th scope="row"><label for="srch_cover">Cover type:</label></th>
<td><?php getCover(); ?></td><br>
<th><label for="srch_author">Author:</th>
<td><?php getAuthors(); ?></td>
</tr>
<tr>
<th scope="row"><label for="srch_language">Language:</label></th>
<td><?php getLanguage(); ?></td>
<th><label for="src_year">Year:</label></th>
<td><?php getYears(); ?></td>
</tr>
<tr>
<th scope="row">Available in:</th>
<td colspan="3"><?php getLocation(); ?></td>
</tr>
<tr>
<td colspan="4"><label for="btn" class="sbm fl_r">
<input type="submit" id="btn" value="Search" />
</label>
</tr>
</form>
<?php if ($tot_rows > 0) { ?>
<table border="0" cellspacing="0" cellpadding="0" class="tbl_repeat">
<tr>
<th scope="col">Book title</th>
<th scope="col" class="col_15">Category</th>
<th scope="col" class="col_15">Author</th>
<th scope="col" class="col_10 al_r">Year</th>
<th scope="col" class="col_10 al_r">Price</th>
</tr>
<?php do { ?>
<tr>
<th scope="col"><?php echo $rows['Title']; ?></th>
<th scope="col"><?php echo $rows['Category']; ?></th>
<th scope="col"><?php echo $rows['Author']; ?></th>
<th scope="col"><?php echo $rows['Year']; ?></th>
<th scope="col"><?php echo $rows['Price']; ?></th>
</tr>
<?php } while($rows = mysql_fetch_assoc($rs)); ?>
</table>
<?php
} else {
if (!empty($queries)) {
echo "<p>There are no records matching your searching criteria.</p>";
} else {
echo "<p>There are currently no records available.</p>";
}
}
?>
</div>
</div>
<body>
</body>
</html>
<?php mysql_free_result($rs); ?>
functions.php
<?php
require_once('database.php');
function getLanguage() {
global $database;
global $conndb;
$sql = "SELECT * FROM languages ORDER BY name ASC";
mysql_select_db($database, $conndb);
$rs = mysql_query($sql, $conndb) or die(mysql_error());
$rows = mysql_fetch_assoc($rs);
$total_rows = mysql_num_rows($rs);
if($total_rows > 0){
echo "<select name=\"srch_language\" id=\"srch_language\">\n";
echo "<option value=\"\">Any language…</option>\n";
do {
echo "<option value=\"".$rows['id']."\"";
getSticky(2, 'srch_language',$rows['id']);
echo ">".$rows['name']."</optio>";
} while($rows = mysql_fetch_assoc($rs));
echo "</select>";
}
mysql_free_result($rs);
}
function getAuthors() {
global $database;
global $conndb;
$sql = "SELECT * FROM authors ORDER BY name ASC";
mysql_select_db($database, $conndb);
$rs = mysql_query($sql, $conndb) or die(mysql_error());
$rows = mysql_fetch_assoc($rs);
$total_rows = mysql_num_rows($rs);
if($total_rows > 0){
echo "<select name=\"srch_author\" id=\"srch_author\">\n";
echo "<option value=\"\">Any author…</option>\n";
do {
echo "<option value=\"".$rows['id']."\"";
getSticky(2, 'srch_author',$rows['id']);
echo ">".$rows['name']."</optio>";
} while($rows = mysql_fetch_assoc($rs));
echo "</select>";
}
mysql_free_result($rs);
}
function getCategories() {
global $database;
global $conndb;
$sql = "SELECT * FROM categories ORDER BY name ASC";
mysql_select_db($database, $conndb);
$rs = mysql_query($sql, $conndb) or die(mysql_error());
$rows = mysql_fetch_assoc($rs);
$total_rows = mysql_num_rows($rs);
if($total_rows > 0){
echo "<select name=\"srch_category\" id=\"srch_category\">\n";
echo "<option value=\"\">Any category…</option>\n";
do {
echo "<option value=\"".$rows['id']."\"";
getSticky(2,'srch_category',$rows['id']);
echo ">".$rows['name']."</optio>";
} while($rows = mysql_fetch_assoc($rs));
echo "</select>";
}
mysql_free_result($rs);
}
function getYears() {
global $database;
global $conndb;
$sql = "SELECT DISTINCT YEAR(date_released) as year FROM books ORDER BY date_released ASC";
mysql_select_db($database, $conndb);
$rs = mysql_query($sql, $conndb) or die(mysql_error());
$rows = mysql_fetch_assoc($rs);
$total_rows = mysql_num_rows($rs);
if($total_rows > 0){
echo "<select name=\"srch_year\" id=\"srch_year\">\n";
echo "<option value=\"\">Any year…</option>\n";
do {
echo "<option value=\"".$rows['year']."\"";
getSticky(2,'srch_year',$rows['year']);
echo ">".$rows['year']."</optio>";
} while($rows = mysql_fetch_assoc($rs));
echo "</select>";
}
mysql_free_result($rs);
}
function getCover(){
global $database;
global $conndb;
$sql = "SELECT * FROM covers ORDER BY name ASC";
mysql_select_db($database, $conndb);
$rs = mysql_query($sql, $conndb) or die(mysql_error());
$rows = mysql_fetch_assoc($rs);
$tot_rows = mysql_num_rows($rs);
if($tot_rows > 0) {
echo "<label for=\"srch_cover-0\">";
echo "<input type=\"radio\" name=\"srch_cover\" id=\"srch_cover-0\"
value=\"0\"";
getSticky(4,'srch_cover',0,1);
echo "/>\nAny</label>";
do {
echo "<label for=\"srch_cover-".$rows['id']."\">";
echo "<input type=\"radio\" name=\"srch_cover\" id=\"srch_cover-".$rows['id']."\"
value=\"".$rows['id']."\"";
getSticky(4,'srch_cover',$rows['id']);
echo "/>\n".$rows['name']."</label>";
} while($rows = mysql_fetch_assoc($rs));
}
mysql_free_result($rs);
}
function getLocation() {
global $database;
global $conndb;
$sql = "SELECT * FROM locations ORDER BY name ASC";
mysql_select_db($database, $conndb);
$rs = mysql_query($sql, $conndb) or die(mysql_error());
$rows = mysql_fetch_assoc($rs);
$total_rows = mysql_num_rows($rs);
if($total_rows > 0){
echo "<ul class=\"chkbx\">";
do {
echo "<li>";
echo "<input type=\"checkbox\" name=\"srch_locations-".$rows['id']."\" id=\"srch_locations-".$rows['id']."\" value=\"".$rows['id']."\"";
getSticky(3,"srch_locations-".$rows['id'],$rows['id']);
echo "/><label for=\"srch_locations-".$rows['id']."\">".$rows['name']."</label>";
echo "</li>";
} while($rows = mysql_fetch_assoc($rs));
echo "</ul>";
}
mysql_free_result($rs);
}
function getSticky($case,$par,$value="",$initial=""){
switch($case) {
case 1: //text field
if (isset($_GET[$par]) && $_GET[$par] !=""){
echo stripslashes($_GET[$par]);
}
break;
case 2: //select dropdown menus
if (isset($_GET[$par]) && $_GET[$par] == $value){
echo " selected=\"selected\"";
}
break;
case 3: //checkbox group
if (isset($_GET[$par]) && $_GET[$par] !=""){
echo " checked=\"checked\"";
}
case 4: //radio buttons
if (isset($_GET[$par]) && $_GET[$par] == $value){
echo " checked=\"checked\"";
} else {
if ($initial !=""){
echo " checked=\"checked\"";
}
}
break;
}
}
?>