Have I got this totally wrong ? It should be simple.
Whatever I try I return the COMPLETE A-Z and never the selected letter only. It seems I am not able to change the variable $name at all.
The relevant code I have made is:
<?php
$alphasearch='';
$spanSearch = range('A','Z');
foreach($spanSearch as $char)
{
$alphasearch.="<span><a href='javascript:ajaxFunction();' name='alphasearch' value='$char'>$char</a></span>\n";
}
?>
<html>
<head>
<script language="javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementById('directory').innerHTML= ajaxRequest.responseText;
}
}
var parameters="char=$name"
ajaxRequest.open("POST", "select_Name.php", true);
ajaxRequest.send(parameters);
}
//-->
</script>
</head>
<body >
<?php
echo $alphasearch;
?>
<br/>
<br/>
<div id="directory" style="margin-left:60px;height:auto;width:25%;background-color:#ffff66">DATABASE INDEX</div>
</body>
</html>
Select_Name.php starts so:
.........
mysql_select_db('xxxx')
or die("Unable to select database: " . mysql_error());
if(isset($_POST['char'])) $name=($_POST['char']);
$query="(SELECT name1 FROM allnames WHERE ..........
Am I anywhere near getting it correct or is the data returned just fortunate ? Could someone explain how I can put it right.