PHP with Mysql
Create PHP page to display user

In This page you get category of user in database.

<?php
$con=mysql_connect('localhost','root','') or die('Mysql not connected');
mysql_select_db('test',$con) or die('DataBase not connected');
?>
<html>
<head>
<script type="text/javascript" src="ajax.js">
</script>
</head>
<body>
<form>
<select name="jobuser" onChange="display(this.value)">
<option value="" selected="selected">-- Select Job Candiate --</option>
<?php
$query="select * from tbl_category";
$query_result=mysql_query($query)or mysql_error();
while($row=mysql_fetch_array($query_result))
{
?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['cat_name']; ?></option>
<?php
}
?>
</select>
</form>
<br />
<div id="showuser">
Candidate show here
</div>
</body>
</html>

Javascript file

Create Javascript file file must be save as ajax.js because we have write ajax.js in the above forms

var XMLHttpRequestObject=false;
function display(user)
{
if(window.XMLHttpRequest)
{
XMLHttpRequestObject=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
XMLHttpRequestObject=new ActiveXObject("Microsoft.XMLHTTP");
}
XMLHttpRequestObject.onreadystatechange=function()
{
if (XMLHttpRequestObject.readyState==4 && XMLHttpRequestObject.status==200)
{
document.getElementById("showuser").innerHTML=XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.open("GET","showuser.php?id="+user,true);
XMLHttpRequestObject.send();
}

PHP page

file must be save as showuser.php

<?php
$con=mysql_connect('localhost','root','') or die('Mysql not connected');
mysql_select_db('test',$con) or die('DataBase not connected');
$id=$_GET["id"];
$query="select * from tbl_user WHERE cat_id = '".$id."'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
?>
<input name="user" type="checkbox" value="<?php echo $row['id']; ?>" /><?php echo $row['user_name']; ?>
<?php
}
?>

DataBase

--
-- Database: `test`
--

-- --------------------------------------------------------

--
-- Table structure for table `tbl_category`
--

CREATE TABLE IF NOT EXISTS `tbl_category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cat_name` varchar(255) COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;

--
-- Dumping data for table `tbl_category`
--

INSERT INTO `tbl_category` (`id`, `cat_name`) VALUES
(1, 'PHP Developer'),
(2, 'Asp.net Developer'),
(3, 'Java Developer'),
(4, 'C++ Programmer');

-- --------------------------------------------------------

--
-- Table structure for table `tbl_user`
--

CREATE TABLE IF NOT EXISTS `tbl_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cat_id` int(11) NOT NULL,
`user_name` char(100) COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=9 ;

--
-- Dumping data for table `tbl_user`
--

INSERT INTO `tbl_user` (`id`, `cat_id`, `user_name`) VALUES
(1, 1, 'Raj'),
(2, 1, 'Aman'),
(3, 2, 'Surjeet'),
(4, 2, 'Nishant'),
(5, 3, 'Rajeev'),
(6, 4, 'Netrapal'),
(7, 4, 'Mitesh pal'),
(8, 4, 'anand');


Previous
Next