Hi!
I´ve tried to create without success a function that would help me to sort contents of a database. I´ll try to explain:
I have 3 SELECT menu options (country, product, responsable), so, if i want to sort all my data by country simply i select the country in the country SELECT (o.0), but in my code it generates the following query:
SELECT * FROM distributors
WHERE country_select_name LIKE country_option_value
That´s perfect! Buuut, if i want to sort the sorted contents by product it would generate:
SELECT * FROM distributors
WHERE country_select_name LIKE country_option_value AND product_select_name LIKE product_option_value
And finally sort by responsable:
SELECT * FROM distributors
WHERE country_select_name LIKE country_option_value AND product_select_name LIKE product_option_value AND responsable_select_name LIKE responsable_option_value
The way I´ve tried to do this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var queryRaw = "SELECT * FROM `distributors` WHERE";
var count = 0;
function changeQuery(cmd, valor, campo){
if(cmd=="Add"){
if(count >= 1){
queryRaw += " AND "+campo+" = "+valor;
}else{
queryRaw += " "+campo+" = "+valor;
}
count = count + 1;
alert(queryRaw+"
"+count);
}
if(cmd=="Rmv"){
}
}
</script>
</head>
<body>
<table summary="">
<tr>
<td>
<select name="nome" onchange="changeQuery('Add', this.options[this.selectedIndex].value, this.name)">
<option>---</option>
<option value="q">q</option>
<option value="s">s</option>
</select>
</td>
<td>
<select name="email" onchange="changeQuery('Add', this.options[this.selectedIndex].value, this.name)">
<option>---</option>
<option value="w">w</option>
<option value="v">v</option>
</select>
</td>
<td>
<select name="profi" onchange="changeQuery('Add', this.options[this.selectedIndex].value, this.name)">
<option>---</option>
<option value="r">r</option>
<option value="q">q</option>
</select>
</td>
</tr>
</table>
</body>
</html>
As you can see, it´s not working.
So, please, help me! (-:
Best regards