Hey i am trying to return books beginning with a certain letter in this case H. But i cant get this code to work at all any help would be great full. HTML
<a href="" id="searchH" name="h" value="h"> <<<< CLICKED
<div id="ack2"></div> <<<<<< DISPLAYED HERE
PHP
<?php
include('db.php');
$letter = "";
$i = 0;
$jsonData = '{"books":[';
if(isset($_POST['letter'])){
$letter = $_POST['letter'];
$sqlString = "SELECT * FROM book WHERE title LIKE '$letter%'";
$query = mysql_query($sqlString) or die (mysql_error());
while ($row = mysql_fetch_array($query)) {
$i++;
$year = $row["year"];
$title = $row["title"];
$author = $row["author"];
$jsonData .= '{ "title":"'.$title.'", "author":"'.$author.'", "year":"'.$year.'" },';
}
$jsonData = chop($jsonData, ",");
$jsonData .= ']}';
echo $jsonData;
}
?>
Ajax/javaScript
$("#searchH").click(function(){
letter = $("#searchH").val();
$.ajax({
type: "POST",
url: "azlistscript.php",
data: "letter ="+letter,
success: function(html){
$("#ack2").html(html);
}
});
});
the PHP file does return the book data if i change the letter value manually it displays the books beginning with H, Just need it to display in a div tag on my html page.
The value of the click event logs no value in the console