<!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=iso-8859-1" />
<title>Untitled Document</title>
<script src="jquery-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript">
function callAjax(va)
{
$.ajax({
url: "responsefile.php?va="+va,
context: document.body,
success: function(result){
document.getElementById('tabl').innerHTML = result;
}
});
}
</script>
</head>
<body>
<?PHP
define('DB_SERVER', 'localhost'); // eg, localhost - should not be NULL
define('DB_USERNAME', 'root'); // MySql user
define('DB_PASSWORD', ''); // MySql user password
define('DB_DATABASE', 'ajax'); // MySql DB
$user = DB_USERNAME;
$pass = DB_PASSWORD;
$server = DB_SERVER;
$dbase = DB_DATABASE;
$conn = mysql_connect($server,$user,$pass);
mysql_select_db($dbase,$conn);
$qu = "select * from month where year=".date("Y");
$res = mysql_query($qu);
$m = 0;
$arr = array();
while($result = mysql_fetch_array($res))
{
$arr[$m]['id'] = $result['id'];
$arr[$m]['month'] = $result['month'];
$arr[$m]['year'] = $result['year'];
$m++;
}
$m = '';
for($i=0;$i<count($arr);$i++)
{
$m.= '<a href=javascript:callAjax('.$arr[$i]['id'].');>'.$arr[$i]['month'].'</a> ';
}
echo $m;
?>
<div id="tabl">
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="jquery-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript">
function callAjax(va)
{
$.ajax({
url: "responsefile.php?va="+va,
context: document.body,
success: function(result){
document.getElementById('tabl').innerHTML = result;
}
});
}
</script>
</head>
<body>
<?PHP
define('DB_SERVER', 'localhost'); // eg, localhost - should not be NULL
define('DB_USERNAME', 'root'); // MySql user
define('DB_PASSWORD', ''); // MySql user password
define('DB_DATABASE', 'ajax'); // MySql DB
$user = DB_USERNAME;
$pass = DB_PASSWORD;
$server = DB_SERVER;
$dbase = DB_DATABASE;
$conn = mysql_connect($server,$user,$pass);
mysql_select_db($dbase,$conn);
$qu = "select * from month where year=".date("Y");
$res = mysql_query($qu);
$m = 0;
$arr = array();
while($result = mysql_fetch_array($res))
{
$arr[$m]['id'] = $result['id'];
$arr[$m]['month'] = $result['month'];
$arr[$m]['year'] = $result['year'];
$m++;
}
$m = '';
for($i=0;$i<count($arr);$i++)
{
$m.= '<a href=javascript:callAjax('.$arr[$i]['id'].');>'.$arr[$i]['month'].'</a> ';
}
echo $m;
?>
<div id="tabl">
</div>
</body>
</html>
No comments:
Post a Comment