Ben AJAX.Request
ile geçirerek değerini almak istiyorum.
<html>
<head>
<script type="text/javascript" src="prototype.js"></script>
<script>
function reload(form)
{
var val = $('seltab').getValue();
new Ajax.Request('Website.php?cat=' +escape(val),
{
method:'get',
onSuccess: function(transport){
var response = transport.responseText ;
$("MyDivDB").innerHTML = transport.responseText ;
alert("Success! \n\n" + response);
},
onFailure: function(){ alert('Something went wrong...') }
});
}
</script>
</head>
<body>
<table border = "1">
<tr>
<td>title</td>
<td>author</td>
<td>pages</td>
</tr>
<?php
include("db_login.php");
$con = mysql_connect($dbhostname,$dbuserid,$dbpassword);
if(!$con)
{
die ("connection failed".mysql_error());
}
$db = mysql_select_db($dbname,$con);
if(!$db)
{
die("Database is not selected".mysql_error());
}
$query ="SELECT * FROM books NATURAL JOIN authors" ;
$result = mysql_query($query);
if(!$query)
{
die("Database is not query".mysql_error());
}
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$title = $row["title"];
$author = $row["author"];
$page = $row["pages"];
echo "<tr>";
echo "<td>$title</td>";
echo "<td>$author</td>";
echo "<td>$page</td>";
echo "</tr>";
}
print "</table>";
echo "<select id = seltab onchange = 'reload(this.form)'>";
$querysel = "SELECT title_id,author FROM authors NATURAL JOIN books";
$result1 = mysql_query($querysel) ;
while($rowID = mysql_fetch_assoc($result1))
{
$TitleID = $rowID['title_id'];
$author = $rowID['author'];
print "<option value = $author>$author\n";
print "</option>";
}
print "</select>";
?>
<div id = "MyDivBD"> </div>
</body>
</html>
Wbsite.php
<?php
$vul = $_GET['cat'];
$selQuery = "SELECT * FROM authors NATURAL JOIN books WHERE author = $vul ";
$selRes = mysql_query($selQuery);
while($selRow = mysql_fetch_assoc($selRes))
{
title author pages
$con = mysql_connect($dbhostname,$dbuserid,$dbpassword);
if(!$con) {
die ("connection failed".mysql_error());
}
$db = mysql_select_db($dbname,$con);
if(!$db) {
die("Database is not selected".mysql_error());
}
$query ="SELECT * FROM books NATURAL JOIN authors" ;
$result = mysql_query($query);
if(!$query) {
die("Database is not query".mysql_error());
}
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$title = $row["title"];
$author = $row["author"];
$page = $row["pages"];
echo "<tr>";
echo "<td>$title</td>";
echo "<td>$author</td>";
echo "<td>$page</td>";
echo "</tr>";
}
print "</table>";
echo "<select id = seltab onchange = 'reload(this.form)'>";
$querysel = "SELECT title_id,author FROM authors NATURAL JOIN books";
$result1 = mysql_query($querysel) ;
while($rowID = mysql_fetch_assoc($result1)) {
$TitleID = $rowID['title_id'];
$author = $rowID['author'];
print "<option value = $author>$author\n";
print "</option>";
}
print "</select>"; ?>
Wbsite.php