Jump to content

Filter Data


june_c21

Recommended Posts

hi,

i got problem when i click on the option value in 1st drop down, the 2nd drop down menu didn't appear. Anything wrong in my php code ?

 

 

html code

<html>
<head>
<title>My Page</title>
<script type="text/javascript">

// SharpAJAX initialization

// Create AJAX object based on browser
if (navigator.appName == "Microsoft Internet Explorer") {
	sharpajax = new ActiveXObject("Microsoft.XMLHTTP");
} else {
	sharpajax = new XMLHttpRequest();
			}

// Initialize
sharpajax.abort();

</script>
<script type="text/javascript">

// My Function

function filter(value) {
     
	// Resets state
	sharpajax.abort();

	// Send command
	sharpajax.open("GET","filter.php?filter="+value);

	// Create input trapping function
	sharpajax.onreadystatechange=function() {
		if (sharpajax.readyState == 4) {
			eval(sharpajax.responseText);
		}
	}

	// Send output
	sharpajax.send("");
}

</script>
<script type="text/javascript">
function createDropdown(container, id) {
	document.getElementById(container).innerHTML = ''+
	'<select name="'+id+'" id="'+id+'">'+
	'</select>';
}
function addDropdownItem(container, value, caption) {
	document.getElementById(container).innerHTML = ''+
	document.getElementById(container).innerHTML +
	'<option value="'+value+'">'+caption+'</option>';
}
</script>
</head>
<body>
<div id="filters_1">
<select name="filter1" id="filter1" onChange="javascript:filter(this.value);">
	<option value="name">Name</option>
	<option value="birthdate">Birthdate</option>
</select>
</div>
<div id="filters_2"></div>
</body>
</html>


 

 

php code

<?php

$myfilter = $_GET['filter'];

// SQL query statements goes here


$host = 'localhost';
$user = 'root';
$password = '';
$dbase = 'drawing';

$dblink = mysql_connect($host,$user,$password);
mysql_select_db($dbase,$dblink);


$filters_2 = $_POST['title'];



$query = "SELECT title FROM drawings ";
  $result1 = mysql_query($query, $dblink);
  while($myrow1 = mysql_fetch_row($result1))
    {
printf("createDropdown('filters_2','filter_2');");
printf("addDropdownItem('filter_2','filtervalue','
filtercaption'");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/96244-filter-data/
Share on other sites

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.